Python Basics Flashcards

1
Q

How to sort a tuple?

A

tuple.sort()

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

How to reverse-sort a tuple?

A

t.sort(reverse=True)

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

What brackets do tuples get?

A

( )

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

What brackets to lists get?

A

[ ]

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

What brackets to dictionaries get?

A

{ }

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

How to create an empty list?

A

empty_list = list()

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

What do you call a tuple with 3 items?

A

a “three-tuple”

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

How to identify a key in a dict and assign a new value?

A

dictionary[“key”] = value

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

How to turn a dictionary into a list of tuples?

A

list_of_tuples = list(dictionary.items())

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

How to add new item to dictionary?

A
counts = dict( )
for line in file_handle :
    words = line.split( )
    for word in words :
        counts[word] = counts.get(word, 0) + 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does this do?

foo = list(dict.items( ))

A

Turns dict into a list of tuples.

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

How to turn a dictionary into a list of tuples?

A

list_of_tuples = list(dict.items( ))

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