18kq1a05d5 30th Dec Assignment

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

--------COUNT OF A STRING-------

list=['a','b','c','abc','bdc','abc']
list_count=list.count('abc')
print(list_count)

Output:
2

------SORTED OF TUPLES-------

listof_tuple=[(1,4),(6,4),(8,5),(2,6)]
listof_tuple.sort()
print(listof_tuple)

OUTPUT:
[(1, 4), (2, 6), (6, 4), (8, 5)]

------REMOVE DUPLICATES------

list1=[1,4,6,4,8,9,3,2,6,5]
print(list1)
list1=list(set(list1))
print(list1)

OUTPUT:
[1, 4, 6, 4, 8, 9, 3, 2, 6, 5]
[1, 2, 3, 4, 5, 6, 8, 9]

---------DICTONARIES ---------
n=5
numbers = {}
for i in range(1, n+1):
numbers[i] = i * i
print(numbers)

OUTPUT:
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

--------DICTIONARIES 1TO15-------
n=15
numbers = {}
for i in range(1, n+1):
numbers[i] = i * i
print(numbers)
OUTPUT:
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121, 12: 144, 13: 169, 14:
196, 15: 225}

--------MERGE DICTIONARIES-------
def Merge(dict1, dict2):
res = {**dict1, **dict2}
return res
dict1={'a':5,'b':3,'c':6}
dict2={'d':5,'f':3,'e':6}
print(Merge(dict1,dict2))

OUTPUT:
{'a': 5, 'b': 3, 'c': 6, 'd': 5, 'f': 3, 'e': 6}

You might also like