Python Flashcards

1
Q

Dalījuma atlikums

A

18 % 7

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Rindot list dilstošā secībā

1) mainot oriģinālu
2) nemainot oriģinālu

A

1) my_list.sort(reverse = True)

2) sorted(my_list, reverse = True)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to remove one pair from the dictionary?

A

del(my_dictionary[‘my_key’])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to get the value corresponding to a key.

A

my_dictionary[‘my_key’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Change a value in a dictionary.

A

my_dictionary[‘my_key’] = 0.2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Add a pair of key and its value to a dictionary.

A

my_dictionary[‘new_key’] = 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Create a dictionary within a dictionary

A

{‘Latvia’: {‘capital’:’Riga’, ‘population’:2 000 000},

‘USA’:{‘capital’: ‘Washington’, ‘population’: 300 000 000}}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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

A

for index, area in enumerate(areas):

print(‘room ‘ + str(index) + ‘: ‘ + str(area))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Given:
europe = {‘spain’:’madrid’, ‘france’:’paris’, ‘germany’:’berlin’, ‘norway’:’oslo’, ‘italy’:’rome’, ‘poland’:’warsaw’, ‘austria’:’vienna’ }

Output:
the capital of france is paris

A

for key, value in europe.items():

print(‘the capital of ‘ + key + ‘ is ‘+ value)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly