Top 5000 python programs examples with solutions - Part 6
Program 61:
Write a program to add two list of strings using list comprehension?
lst1=['hello','welcome','india']
lst2=['everyone','all']
lst3=[a+b for a in lst1 for b in lst2]
print(lst3)
Program 62:
Write a program to generate a set from a string whose length is more than 3?
var='hello world python programs is for a beginners'
varset={a for a in var.split() if len(a) > 3}
print(varset)
Program 63:
Write a program to uppercase a key,multiply values from dictionary?
dc={'a':1,'b':2,'c':3,'d':4,'e':5}
b={k.upper():v*100 for k,v in dc.items()}
print(b)
Program 64:
Write a program to capitalize() keys in dictionary?
dc={'apple':1,'ball':2,'cat':3,'dog':4,'elephant':5}
b={k.capitalize():v*v for k,v in dc.items()}
print(b)
Program 65:
Write a program to count lower and upper words in a string?
def upper_lower_count(s): dc={'UPPER':0,'LOWER':0} lst=s.split() for i in lst: if i.isupper(): dc['UPPER']+=1 elif i.islower(): dc['LOWER']+=1 return(dc) var=upper_lower_count('Hello WORLD PYTHON programs on simple PAGE') print(var)
Program 66:
Write a program to find out intersection of two list?
def intersection_list(l1,l2):
l3=list(set(l1) & set(l2))
return(l3)
l1=[1,2,3,10,20,4]
l2=[2,8,9,10,-1,4]
l4=intersection_list(l1,l2)
print(l4)
Program 67:
Write a program that contains (i,i*i ) dictionary comprehension on below input?
var=int(input('Enter the input value'))
d={}
for i in range(1,var+1):
d[i]=i*i
print(d)
Program 68:
Write a program to split and sort using list comprehension?
its=[i for i in input().split(',')]
its.sort()
print(','.join(its))
Program 69:
Write a program to add two list of string using list comprehension?
lst=[(x,y) for x in range(2,7) for y in range(2,7)]
print(lst)
Program 70:
Write a program to add two list of string using list comprehension?
lst=[(x,y) for x in range(2,7) for y in range(2,7)]
print(lst)
Labels: Top 5000 python programs examples with solutions Part 6
0 Comments:
Post a Comment
Note: only a member of this blog may post a comment.
<< Home