#Practice 1
library = {
'1984': 3,
'Python Crash Course': 7,
'Deep Work': 2
}
print('Books names are: ')
for key in library.keys():
print(key)
#way number1 for sum
_sum = sum(library.values())
print(_sum)
#way number2 for sum(just for more being creative ofcoure way number 1 is better)
_list = []
for value in library.values():
_list.append(value)
print(sum(_list))
for key, value in library.items():
if value < 5:
print(f'{key}: {value}')
#Pracrice 2
users = dict(ali = "admin", mina = 'user')
backup_users = users.copy()
print(users == backup_users) #True
print(users is backup_users) #False
users.clear()#{}
default_users = dict.fromkeys(['ali', 'mina'], 'guest') #{'ali': 'guest', 'mina': 'guest'}
weather = {
'Tehran': 25,
'Mashhad': 20,
'Shiraz': 28
}
weather.get('Shiraz') #28
weather.get('Esfahan') #None
weather['Esfahan'] #KeyError : 'Esfahan'
weather['Tehran'] #25
_remove = weather.pop('Mashhad')
print(_remove) #20
print(weather) #{'Tehran': 25, 'Shiraz': 28}
اینم کد هک روبیکا