Monday, 4 May 2020

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...


Sunday, 3 May 2020

Integer and Decimal value in C#

In this blog, we will discuss about
  • C# Integer Datatypes
  • C# Decimal Datatypes
C# Integer Datatypes :
  • We can only store whole number in them
  • Whole Number mean number without any decimal such as 34, 204, 35 etc
List of C# Integer Datatypes
  • byte
  • short
  • int
  • long
 The difference between all these integer datatype how big value we can store in it.

- Byte 
  • sbyte can store value between -128 and 127.
  • byte can store value between 0 and 255.
- Shot 
  • short can store between -32768 and 32767.
  • ushort can store between 0 and 65535.
- Int 
  • int can stor value between -2147483648 and 2147483647.
  • uint can store value between0 and 4294967295.
- Long 
  • long can store value between -9223372036854775808 and 9223372036854775807.
  • ulong can store value between 0 and 18446744073709551615.
How to declare variables in C#
- General Syntax
      DataType VariableName = value;

Examples
  • sbyte scoreSbyte;
  • byte ageByte;
  • short studentIdShort = 5;
  • int studentIdInteger = 43;
Design Example :
- What will be datatype for Age?

Human can live these days at most, 120. Make it 150. so byte is best.
But In older days from history, we find that many people lived for around 1000 years, so Short is best.
What if the Age is relating to Historical Site or Historical Events (Big Bang), which may be thousands or million of years old then int is best.

C# Decimal Datatypes:
  • We can store decimal numbers in them
  • We can also store Whole number in them
  • For example , 34.5, 204.3, 35.7 etc.
List of C# Decimal Datatypes
  • float
  • double
The difference between all these decimal datatype how big value we can store in it.


Example 
  • float salaryFloat = 101.5f;
  • decimal salaryDecimal = 101.25m;
  • double salaryDouble = 101.5;

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/

Last Stone Weight | Python

Code: class Solution: def lastStoneWeight(self, stones: List[int]) -> int: while(len(stones)>1): heaviest=max(stones); stones.remove(heaviest); heavier=max(stones); stones.remove(heavier); if(heaviest!=heavier): stones.append(heaviest-heavier); if(len(stones)==0): return 0; else: return stones[0];

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

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

Move Zeroes | Python

Code: class Solution: def moveZeroes(self, nums: List[int]) -> None: g=nums.count(0); i=0; while(i<g): nums.remove(0); nums.append(0); i=i+1;

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

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


Counting Elements | Python

Code :

class Solution: def countElements(self, arr: List[int]) -> int: output=0; for i in arr: if(i+1 in arr): output+=1; return output;
Python for beginners: https://www.youtube.com/watch?v=egq7Z..

Telegram: https://t.me/clcoding_python


Program to find whether a no is power of two or not | Python

Prerequisite: Data Type Conversion | Python | Castor Classes https://www.youtube.com/watch?v=z8yw6... Turn off the rightmost set bit | Python | Castor Classes https://www.youtube.com/watch?v=ol4VW... Relationship between binary representation of n & n-1 | Python | Castor Classes https://www.youtube.com/watch?v=iTxc9... Python for beginners: https://www.youtube.com/watch?v=egq7Z..

Telegram: https://t.me/clcoding_python

Escape Sequence in Python

Escape Sequence - 

Escape sequences are control character used to move the cursor and print characters such as ',".\ and so on.


















Friday, 1 May 2020

Python Input() Function

Input( )

Python provides us the facility to take input from user using Input( ) function. This function prompts the user to input a value.

For example :

Name = input("Enter Your Name");
print(Name);

Output will be the name as entered by the user.

Let us take the example again:

name = input("Enter Your Name:");
print("Welcome Mr.",name);

Here suppose the user enter the name as "xyz Kumar" so the variable name will contain xyz Kumar. In such case the output of the program will be:

Output      Welcome Mr. xyz Kumar


 Please note that the input( ) accepts the input only in string format. so, if any mathematical calculation is to be performed, we need to convert the input to integer format. for converting the input to integer format Python provide us a function called :

Program without using int( ) function :

a = input ("Enter 1st Number:");
b =  input("Enter 2nd Number:");
c = a+b;
print("Addition =",c);

In this case if the value of a & b as given by user is 5 & 6 respectively then the output will be 56. As 5 & 6 will be treated as string and not integer.

Program using int( ) function

a = int(input("Enter 1st Number:"));
b = int(input("Enter 2nd Number:"));
c=a+b;
print("Addition=",c);

 In this case if the value of a & b as given by user is 5 & 6 then output will be 11 as we have converted the input from string to integer format.



Thursday, 30 April 2020

Turn off the rightmost set bit | Python

Question: Write a program that unsets the rightmost set bit of an integer. Input: 12 Output: 8 Input: 7 Output: 6 Simple code: n=int(input()); print(n & (n-1)) Prerequisite: Data Type Conversion | Python | Castor Classes https://www.youtube.com/watch?v=z8yw6... Relationship between binary representation of n & n-1 | Python | Castor Classes https://www.youtube.com/watch?v=iTxc9... Python for beginners: https://www.youtube.com/watch?v=egq7Z..

Join: t.me/clcoding_python

Popular Posts

Categories

100 Python Programs for Beginner (49) AI (34) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (173) C (77) C# (12) C++ (82) Course (67) Coursera (226) Cybersecurity (24) data management (11) Data Science (128) Data Strucures (8) Deep Learning (20) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (34) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (59) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (3) Pandas (4) PHP (20) Projects (29) Python (929) Python Coding Challenge (351) Python Quiz (22) Python Tips (2) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (3) Software (17) SQL (42) UX Research (1) web application (8) Web development (2) web scraping (2)

Followers

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