Python Basics Flashcards
1
Q
How to sort a tuple?
A
tuple.sort()
2
Q
How to reverse-sort a tuple?
A
t.sort(reverse=True)
3
Q
What brackets do tuples get?
A
( )
4
Q
What brackets to lists get?
A
[ ]
5
Q
What brackets to dictionaries get?
A
{ }
6
Q
How to create an empty list?
A
empty_list = list()
7
Q
What do you call a tuple with 3 items?
A
a “three-tuple”
8
Q
How to identify a key in a dict and assign a new value?
A
dictionary[“key”] = value
9
Q
How to turn a dictionary into a list of tuples?
A
list_of_tuples = list(dictionary.items())
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
11
Q
What does this do?
foo = list(dict.items( ))
A
Turns dict into a list of tuples.
12
Q
How to turn a dictionary into a list of tuples?
A
list_of_tuples = list(dict.items( ))