text
stringlengths 0
312
|
---|
a=(2,3,1,5) |
tuple_sorted = sorted(a) |
print(tuple(tuple_sorted)) |
# write a python program to multiple two list values |
l1=[1,2,3] |
l2=[4,5,6] |
print('multiply two list values:',[x*y for x in l1 for y in l2]) |
# write the list comprehension to pick out only negative integers from a given list ‘l’. |
l1=[1,2,3,-4,-8] |
print('negative integers:', [x for x in l1 if x<0]) |
# write a python program to convert all list elements to upper case |
s=["pune", "mumbai", "delhi"] |
print([(w.upper(), len(w)) for w in s]) |
# write a python program to expalin python zip method |
l1=[2,4,6] |
l2=[-2,-4,-6] |
for i in zip(l1, l2): |
print(i) |
# write a python program to add two list using python zip method |
l1=[10, 20, 30] |
l2=[-10, -20, -30] |
l3=[x+y for x, y in zip(l1, l2)] |
print('added two list:',l3) |
# write a list comprehension for number and its cube |
l=[1, 2, 3, 4, 5, 6, 7, 8, 9] |
print([x**3 for x in l]) |
# write a list comprehension for printing rows into columns and vv |
l=[[1 ,2, 3], [4, 5, 6], [7, 8, 9]] |
print([[row[i] for row in l] for i in range(3)]) |
# write a list comprehension for printing rows into columns and vv |
def unpack(a,b,c,d): |
print(a+d) |
x = [1,2,3,4] |
unpack(*x) |
# write a python program to use python lambda function |
lamb = lambda x: x ** 3 |
print(lamb(5)) |
# write a python program to multiply a string n times |
a = 'python' |
print(a*5) |
# write a python to check two numbers are greater than or equal or less than |
def maximum(x, y): |
if x > y: |
return x |
elif x == y: |
return 'The numbers are equal' |
else: |
return y |
print(maximum(2, 3)) |
# write a python to dict to zip and print as dictionary elements in original form |
a={"a":1,"b":2,"c":3} |
b=dict(zip(a.values(),a.keys())) |
print(b) |
# write a python program to delete an dictionary element |
a={1:5,2:3,3:4} |
a.pop(3) |
print(a) |
# write a python program to check two dictionary are equal or not |
d1 = {"john":40, "peter":45} |
d2 = {"john":466, "peter":45} |
d1 == d2 |
# write a python program to print only dictionary keys as list |
d = {"john":40, "peter":45} |
print(list(d.keys())) |
#write a python program to check two lists are equal or not |
a=[1, 4, 3, 5, 2] |
b=[3, 1, 5, 2, 4] |
print(a==b) |
#write a python program to check two lists are equal or not |
a=frozenset(set([5,6,7])) |
print(a) |
#write a python program to sum the set of unqiue elements |