Dictionary: Dict ('Name': 'Geeks', 1: (1, 2, 3, 4) )
Dictionary: Dict ('Name': 'Geeks', 1: (1, 2, 3, 4) )
Dictionary
d = dict() # or d = {}
Dict = {1: 'Geeks', 2: 'For', 3:{'A' : 'Welcome', 'B' : 'To', 'C' : 'Geeks'}}
Dict[0] = 'Geeks'
Dict[2] = 'For'
Dict[3] = 1
Dict[2] = 'Welcome'
print(Dict['name'])
del Dict[1]
# Nested Dictionary
del Dict['A'][2]
# Deleting a Key
Dict.pop(5)
Dict.clear()
print (str(dic))
print (dic.items())
dict1 = [ 1, 3, 5, 6 ]
print (len(dic1))
print (type(dic1))
dic3 = {}
dic3 = dic1.copy()
# printing new dictionary
print (dic3.items())
dic1.clear()
d['xyz'] = 123
d['abc'] = 345
dic1.update(dic2)
print (str(dic1))
# Initializing sequence
dict = dict.fromkeys(sequ,5)
{'Age': 5, 'Name': 5, 'ID': 5}
if dict.has_key('Name'):
D1={}
D2={}
D1.update(D2)
import operator
d = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0}
print(color_dictionary)
key_max = max(my_dict.keys(), key=(lambda k: my_dict[k])) NOTE: KEY DEFINE S THE CRITERIA OF FINDING MAX AND MIN
key_min = min(my_dict.keys(), key=(lambda k: my_dict[k])) FOR EXAMPLE IN THIS CASE OUR CRITERIS IS THAT FINDING MAX AND MIN THROUGH
OR
A=list(my_dic.values())
B=list(my_dict.keys())
Print b[A.index(max(A))]
https://www.mfitzp.com/article/python-dictionaries/
:List:
List = []
# Addition of Elements
List.append(1)
List.append(2)
List.append(3)
[1, 2, 4]
# using Iterator
List.append(i)
[1, 2, 4, 1, 2, 3]
List.append((5, 6))
List.append(List2)
print(List[0])
print(List[2])
print(List[-1])
List=[1, 2,…..]
Now output is
List=[3, 4,…}
List=[1, 2, 3, 4]
Print(list + [5, 21 ])
List=[1, 2, 3, 4, 5, 21]
List.remove(i)
List.pop()
# Creating a List
Sliced_List = List[:-6]
Sliced_List = List[5:]
Sliced_List = List[:]
Sliced_List = List[::-1]
print(list1.index(4))
print(list2.index('cat'))
print(list1.index([9, 8, 7]))
list=[1, 2, 3, 4, 5]
print(list[1] + list[2])
output is (BC)
#TIPS
x=[1, 2, 3, 4] x=[1 , 2, 3, 4]
y=x y=list(x)
numpy.core.defchararray.index(arr, substring, start=0, end=None): Finds the lowest index of the sub-
string in the specified range But if substring is not found, it raises ValueError.
import numpy as np
import numpy as np
list comprehension:
1=[expression for variable in range]
List=[] a/c to comprehension square=[i**2 for x in
For x in range(1, 101): print(square)
Square.append(x**2)
Print(square)
2=[expression for variable in range if <cond>]
If value>2000
Print(tittle)
4=[expression for variable-1 in range-1 and variable-2 in range-2]
Cartesion product:
A=[1, 2, 3, 4, 5]
B=[1, 2, 3, 4, 5]
Print(list)
no=a[:-1]
if a[-1]=="F":
print(c,"C")
elif a[-1]=="C":
c=int((1.8)*(1/no -32))
print(c,"F")
else:
print("incorrect input")