Assignment Python || CodexRitik

                                 Python Assignment

  • 1. Program to accept the strings which contains all vowels
👉Solution:
#Program to accept the strings which contain all vowels.
#written by CodexRitik
STRING_SETS=set()
vowels ={'a','e','i','o','u'}
VOWELS={'A','E','I','O','U'}
for i in range(int(input("No.of String element = "))):   
    element=input()
    word=set(element)
    K=(word & vowels)
    L=(word & VOWELS)
    if(K == vowels):
        STRING_SETS.add(element)    
    elif(L == VOWELS):
        STRING_SETS.add(element)
    else:
        print(element,"is reject")
        break
print(STRING_SETS)

  • 2.Pyhton program to find common elements in three lists using sets.
👉Solution:
#python program to find common elements in three lists using sets
#written by CodexRitik
S=[set(map(int,input().split())) for i in range(3)]#nested list
for i in S:
    s1=S[0]
    s2=S[1]
    s3=S[2]
    c_e=s1&s2&s3
print(c_e)
for j in c_e:
    print("common_element = ",j)

  • 3.Find missing and additional values in two lists.
👉Solution:
#Find missing and additional values in two lists
L1=list(map(int,input().split()))
L2=list(map(int,input().split()))
mis1=[];mis2=[];add1=[];add2=[]
mis1=[i for i in L2 if(i not in L1)]
mis2=[j for j in L1 if(j not in L2)]
add1=mis2;add2=mis1
print("\nMissing value in List1 = ",mis1,"\nMissing value in List2 = ",mis2)
print("\nAdditional value in List1 = ",add1,"\nAdditional Value in List2 = ",add2)


  • 4.Minimum number of subsets with distinct elements using Counter
👉Solution:

#Minimum number of subsets with distinct elements using counter
#written by codexritik
def subset(List, n): 
    res = 0
    List.sort()
    for i in range(0, n) : 
        count = 1
        for i in range(n - 1): 
            if List[i] == List[i + 1]: 
                count+=1
            else
                break
        res = max(res, count) 
      
    return res  
List = list(map(int,input().split())) 
n = len(List) 
print(subset(List, n)) 
  • 5.Program to count number of vowels using sets in given string
👉Solution:

#Program to count number of vowels using sets in given string
#written by CodexRitik
S=input("Enter a String = ")
v={'a','e','i','o','u'}
V={'A','E','I','O','U'}
if(S.islower()):
    L=[i for i in S if(i in v)]
    print("No. of Vowels = ",len(L))
else:
    L1=[j for j in S if(j in V)]
    print("No. of Vowels = ",len(L1))
  • 6.Python set operations(union,intersection,difference and symmetric difference)
👉Solution:

#PYTHON SET OPERATIONS (UNION,INTERSECTION,DIFFERENCE AND SYMMETRIC DIFERENCE)
#WRITTEN BY CODEXRITIK
SET =set(map(int,input().split()))#single line set input method
SET1=set(map(int,input().split()))
print("\nUnion = ",SET | SET1,"\nIntersection = ",SET&SET1)
print("\nDifference = ",SET-SET1,SET1-SET,"\nSYMMETRIC_DIFFERENCE = ",SET^SET1)






🙏THANKS FOR VISIT THIS BLOG🙏







Assignment Python || CodexRitik Assignment Python || CodexRitik Reviewed by CodexRitik on April 08, 2020 Rating: 5

No comments:

Powered by Blogger.