Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Thursday 7 May 2020

end parameter in print() | Python

Handling Exceptions | Python

You can catch an exception by implementing the try—except construct. This construct is broken into 2 major parts: • try block. The try block indicates the code which is to be monitored for the exceptions listed in the except expressions. • except clause. You can use an optional except clause to indicate what to do when certain classes of exception/error occur (e.g. resolve the problem or generate a warning message). There can be any number of except clauses in sequence checking for different types of error/exceptions. For more detail explanation , check this below link: https://docs.python.org/3/tutorial/er... Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Mathematical Operations on Set | Python

Nth term of GP | Python

Code: a=int(input('Enter the first term')); b=int(input('Enter the second term')); N=int(input('Enter the n value')); # 2 4 8 16 32 r=b/a; s=a*r**(N-1); print(s); Prerequisite: Power of a number | Python | Castor Classes https://www.youtube.com/watch?v=omFAv... Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Is Subsequence | Python

Prerequisite: String in Python | Part 2.3 | Castor Classes https://www.youtube.com/watch?v=65z1V... Check the problem statement here: https://leetcode.com/problems/is-subs... Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Code:


class Solution:
    def isSubsequence(self, s: str, t: str) -> bool:
        g=0;
        for i in s:
            if(i in t):
                rs=t.index(i);
                t=t[rs+1:];
            else:
                g+=1;
        if(g==0):
            return True;
        else:
            return False;


Set | Python

help & tab completion | Python

Topics discussed in this video: a)Getting help in Python & some important methods related to String-- 1).isalpha() 2).isalnum() 3).islower() 4).isupper() b)tab completion in Python Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Tuesday 5 May 2020

what are the difference between LIST , TUPLE and SET in python ?


The tuple, list, set, dictionary are trying to solve the most important problems in programming, called, storage of data and retrieval of stored data in a way that is both easy to use, to code and to read for the programmers.
The big problems are:
- space availability
- insertion
- searching by value or position
- updating
- make the operations faster for big/huge data sets
Tuple:
When you only store data that you aren't changing and don't need to do search by value as you know the position.
List:
When you store data that you changing, inserting if fast and don't need to do search/update by value as you know the position
Set:
When you store data that changes from times to time, but most importantly you need very fast search by value as you don't know position then you use sets.The search is very fast as the set is indexed in memory and fast binary search used. Inserting and deletion is slow.
Dictionary:
When you need fast search, data doesn't change often, few updates and inserts. Is just advanced set where you store a group of key and value and search by the key.

Monday 4 May 2020

Largest Number At Least Twice of Others | Python

Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Code:


class Solution:
    def dominantIndex(self, nums: List[int]) -> int:
        f=max(nums);
        rs=nums.index(f);
        u=[];
        g=0;
        for i in nums:
            if(i!=f):
                u.append(i);
        if(len(u)!=0):
            g=max(u);
        if(f>=2*g):
            return rs;
        else:
            return -1;


Ransom Note | Python

Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Code:


class Solution:
    def canConstruct(self, ransomNote: str, magazine: str) -> bool:
        g=0;
        for i in ransomNote:
            t=ransomNote.count(i);
            s=magazine.count(i);
            if(t>s):
                g+=1;
        if(g==0):
            return True;
        else:
            return False;


Telegram: https://t.me/clcoding_python 
https://www.facebook.com/pirawenpython/ 
https://www.facebook.com/groups/piraw...

Search Insert Position | Python

Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Code:


class Solution:
    def searchInsert(self, nums: List[int], target: int) -> int:
        if(target in nums):
            return nums.index(target);
        else:
            if(target<min(nums)):
                return 0;
            elif(target>max(nums)):
                return len(nums);
            else:
                g=0;
                m=0;
                while(g<len(nums)):
                    if(nums[g]>target):
                        m=g;
                        break;
                    g=g+1;
                return m;


Intersection of Two Arrays | Python

Check the problem statement here: The intersection of Two Arrays: https://leetcode.com/problems/interse... Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Code:


class Solution:
    def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
        output=[];
        for i in nums1:
            if(i in nums2 and i not in output):
                output.append(i);
        return output;


Telegram: https://t.me/clcoding_python 
https://www.facebook.com/pirawenpython/ 
https://www.facebook.com/groups/piraw...

Jewels and Stones | Python

Prerequisites for solving this particular question: String Immutability & count method | Python | Castor Classes https://www.youtube.com/watch?v=Am1vX... Iterate over a list & string | List in Python | Part 4 | Castor Classes https://www.youtube.com/watch?v=4Zrfk... You can get the problem statement here: https://leetcode.com/problems/jewels-... Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Code:


class Solution:
    def numJewelsInStones(self, J: str, S: str) -> int:
        c=0;
        for i in J:
            c+=S.count(i);
        return c;


If Expressions in Python

Prerequisite:

if else command | Python 
https://www.youtube.com/watch?v=9GJWK...

Java code used in this video:

import java.util.*;
public class Hello {
public static void main(String args[])
{
 Scanner obj=new Scanner(System.in);
 int x=obj.nextInt();
 String s=(x%2==0)?"Even":"Odd";
 System.out.println(s);
}
}

Python for beginners:
https://www.youtube.com/watch?v=egq7Z...

Telegram: https://t.me/clcoding_python 
https://www.facebook.com/pirawenpython/ 
https://www.facebook.com/groups/piraw...

None value in Python

Separate 0’s and 1’s in an array | Python

Python for beginners: 
https://www.youtube.com/watch?v=egq7Z..

Code:


l=int(input());

i=0;

m=[];

zeros=0;

while(i<l):

    y=int(input());

    if(y==0):

        zeros+=1;

    m.append(y);

    i+=1;

i=0;

while(i<l):

    if(i<zeros):

        m[i]=0;

    else:

        m[i]=1;

    i=i+1;

print(m);


Telegram: https://t.me/clcoding_python 
https://www.facebook.com/pirawenpython/ 
https://www.facebook.com/groups/piraw...

Find first set bit | Python

Python for beginners:
https://www.youtube.com/watch?v=egq7Z...

Code:


t=int(input());
i=0;
while(i<t):
    a=int(input());
    rs=bin(a)[2:];
    y=list(rs);
    y.reverse();
    if('1' in y):
        io=y.index('1');
        print(io+1);
    else:
        print(0);
    i=i+1;


Telegram: https://t.me/clcoding_python 
https://www.facebook.com/pirawenpython/ 
https://www.facebook.com/groups/piraw...


Saturday 2 May 2020

List membership Testing using in | Part 8 | Python

Code: class Solution: def checkIfExist(self, arr: List[int]) -> bool: g=0; for i in arr: if(i*2 in arr and i!=0): g=1; break; elif(i*2 in arr and arr.count(2*i)>=2): g=1; break; if(g==0): return False; else: return True;

Problem Link: Check If N and Its Double Exist: https://leetcode.com/problems/check-i... Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Prime Number of Set Bits in Binary Representation | Python

Prerequisite: Brian Kernighan’s Algorithm | Python | Castor Classes https://www.youtube.com/watch?v=DUSCd... Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Telegram: https://t.me/clcoding_python
https://www.facebook.com/pirawenpython/

Brian Kernighan’s Algorithm | Python

Code: class Solution: def countBits(self, num: int) -> List[int]: bum=[]; i=0; while(i<=num): bum.append(i); i=i+1; output=[]; for i in bum: count=0; while(i>0): i=i&i-1; count+=1;#count=count+1; output.append(count); return output;

Number of 1 Bits https://leetcode.com/problems/number-... Counting Bits https://leetcode.com/problems/countin... Code is given in the comment section. Python for beginners: https://www.youtube.com/watch?v=egq7Z...

Telegram: https://t.me/clcoding_python https://www.facebook.com/pirawenpython/

Popular Posts

Categories

AI (27) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (115) C (77) C# (12) C++ (82) Course (62) Coursera (178) coursewra (1) Cybersecurity (22) data management (11) Data Science (90) Data Strucures (6) Deep Learning (9) Django (6) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (5) flutter (1) FPL (17) Google (19) Hadoop (3) HTML&CSS (46) IBM (25) IoT (1) IS (25) Java (92) Leet Code (4) Machine Learning (44) Meta (18) MICHIGAN (5) microsoft (3) Pandas (3) PHP (20) Projects (29) Python (746) Python Coding Challenge (201) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (40) UX Research (1) web application (8)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses