Python Flashcards
Dalījuma atlikums
18 % 7
Rindot list dilstošā secībā
1) mainot oriģinālu
2) nemainot oriģinālu
1) my_list.sort(reverse = True)
2) sorted(my_list, reverse = True)
How to remove one pair from the dictionary?
del(my_dictionary[‘my_key’])
How to get the value corresponding to a key.
my_dictionary[‘my_key’]
Change a value in a dictionary.
my_dictionary[‘my_key’] = 0.2
Add a pair of key and its value to a dictionary.
my_dictionary[‘new_key’] = 3
Create a dictionary within a dictionary
{‘Latvia’: {‘capital’:’Riga’, ‘population’:2 000 000},
‘USA’:{‘capital’: ‘Washington’, ‘population’: 300 000 000}}
Write a for loop that writes out
room x: y
given:
areas = [11.25, 18.0, 20.0, 10.75, 9.50]
where x is the index of the element in a list
and y is the value in the list with the according index
for index, area in enumerate(areas):
print(‘room ‘ + str(index) + ‘: ‘ + str(area))
Given:
europe = {‘spain’:’madrid’, ‘france’:’paris’, ‘germany’:’berlin’, ‘norway’:’oslo’, ‘italy’:’rome’, ‘poland’:’warsaw’, ‘austria’:’vienna’ }
Output:
the capital of france is paris
for key, value in europe.items():
print(‘the capital of ‘ + key + ‘ is ‘+ value)