final Flashcards

(64 cards)

1
Q

syntax for dictionary is what?

A

{key:value}

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

example of what:
p = {“p1”:”john”,”p2”:”anna”}

A

dictionary

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

do dictionaries allow duplicates, what will it do if you make duplicates

A

no it will overwrite existing item with same key

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

what accessing methods can you use for dictionary

A

get, keys, values, items

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

what does the keys() method do?

A

returns a list of all the keys in the dictionary

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

what does the values() method do?

A

returns a list of all the values in the dictionary

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

what does the items() method do?

A

returns items in a dictionary as tuples in a list

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

how do you add a single item to a dict using index

A

Dict[“key”] = “value”

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

what does the .update method do?

A

it adds/changes dict items

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

what delete methods can you use for dictionary items

A

pop, popitem, del, clear

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

what does the pop() method do
and syntax

A

removes item with specified key
Dict.pop(“key”)

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

what does popitem() do
and syntax

A

removes the last inserted item, does not take arguments
Dict.popitem()

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

what does the del method do
syntax

A

removes the item with specified key, or whole dictionary
del Dict[“key”]
del Dict

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

what does the clear method do

A

empties the dictionary

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

can you use concatentation (+) or repetition (*) on a dictionary

A

No

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

what does len() return for dictionary

A

the number of key-value pairs

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

what does sum() return for dictionary

A

summation of all the keys (only integers or float)
sum(Dict.values())

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

max() and min() returns?

A

the max and min keys in the dict (only if keys are the same type)
max(Dict.values())

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

what does sorted do?

A

returns a list of sorted keys in the dictionary (only if keys are not mixed)
sorted(Dict.items())

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

what comparison operators can you use on dictionaries

A

== and !=

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

how can you slice with a dictionary

A

turn it into a list and then turn it back to dict

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

which data structure(s) are represented by { }

A

set and dictionary

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

which data structure(s) are represented by ( )

A

tuple

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

which data structure(s) are represented by [ ]

A

list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
which data structures are mutable
list and dictionary set can add or delete but not reassign
26
which data structure is immutable
tuple
27
which data structures are ordered
list, tuple, dictionary
28
which data structures support indexing
list, tuple, and dictionary using keys
29
which data structures support slicing
list and tuple
30
syntax to create a 0-d numpy array
arr = np.array(#)
31
syntax to create 2-d numpy array
arr = np.array( [ [1,2,3,4], [5,6,7,8], [9,10,11,12]])
32
can numpy arrays have different data types
no they all have to be the same
33
once created can the size of a numpy array change
no it has to be the same
34
what does np.arange() do and syntax
creates and array that contains a range of evenly spaced intervals np.arange(start,stop,step)
35
what does linspace() do and syntax
creates an array with n values spaced evenly in specified interval np.linspace(start,stop, num = n) STOP VALUE IS INCLUDED
36
what is a series
a one dimensional array holding data of any type
37
series syntax
pd.Series(data, index=index)
38
what is a dataframe
a two dimensional data structure with labeled rows and columns
39
dataframe syntax
s = pd.DataFrame(data,index=index, columns = columns)
40
what method is used to plot a line graph in matplotlib
plt.plot()
41
main purpose of OOP
to model real world entities using objects and classes
42
how do you create an object of a given class in python
my_object = MyClass()
43
which function is used to retrieve data from an API using the requests library
requests.get()
44
which method is used to read all the lines of a file into a list
readlines()
45
what is the advantage of numpy array over python lists
numpy arrays support element wise mathematical operations
46
can data frames support indexing or slicing
yes
47
can data frames hold data of multiple types
yes
48
can data frames hold different types of data in different columns
yes
49
can data frames handle missing data
yes
50
how do you create a numpy array with values from 0 to 8
np.arange(0,9)
51
what pandas method would you use to drop missing values from a data frame
df.dropna()
52
what does .sort() return
None
53
when you want to give a name to an attribute of a class, say, Name, how do you create it in the driver code
with the set() method
54
handling: w
write mode. opens a file for writting, existing data will be overridden
55
handling: r
read mode. opens a file for reading
56
handling: a
append mode. opens a file for appending, does not override existing data
57
handling x:
create mode. creates the specified file, returns an error if the file exists
58
handling: r+
open the file for reading and writing. does not override the existing data
59
handling: w+
open the file for reading and writing. overwrites the previous file if one exists
60
handling: a+
open the file for reading and writing. creates the file if it does not exist. does not override existing data
61
what is serializing
json takes python hierarchies and converts them to string representations
62
what is deserializing
reconstructing data from string representation
63
what do API calls usually return
json strings
64
what does json.dumps() do?
convert a python object into a json string