Invalid dictionary
Error: using a list as a key is not allowed hence use tuple
dictionary cannot have duplicate keys
my_dict = {
1: "Hello",
(1, 2): "Hello Hi",
}
print(my_dict)
a= my_dict.items()
print(a)
v=[] k=[] for i,j in zip(my_dict.values(),my_dict.keys()): v.append(i) k.append(j)
print(v,k)
country_capitals = {
"United States": "New York",
"Italy": "Naples",
"England": "London"
}
print(country_capitals)
print("=====================================")
country_capitals["Italy"] = "Rome"
print(country_capitals)
country_capitals = {
"United States": "New York",
"Italy": "Naples"
}
print("=====================================")
country_capitals["Germany"] = "Berlin"
print(country_capitals)
print("=====================================")
country_capitals = {
"United States": "New York",
"Italy": "Naples" ,
"mars":"planet",
"earth":"ours"
}
print(country_capitals)
print(country_capitals.pop('Italy'))
del country_capitals["United States"]
print(country_capitals.popitem())
print(country_capitals)
print("=====================================")
a=country_capitals.copy()
print(a,country_capitals)
a.clear()
print(a,country_capitals)
print("=====================================")
print(country_capitals)
country_capitals['mars']='solar'
print(country_capitals)
a = sorted(dict_name.items(), key=lambda x:x[0]) # by Key
a = sorted(dict_name.items(), key=lambda x:x[1]) # by Value