The false bible of commands Flashcards

1
Q

what does random() do?

A

random real number between 0 and 1 (not inclusive of 1, but 0 works)

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

what does randint() do?

A

returns random integer between a and b INCLUSIVELY (and doesnt work when not provided a range)

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

what happens if you get an undefined error?

A

you redefined a core python function/something and is now uncallable, reset python immediately

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

are while true loops allowed?

A

NAH

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

.title()

A

capitalizes first letter, lowercases all others

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

what does the keyword del do?

A

deletes a variable from memory

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

repr()

A

returns exactly what string you put in, NOT including quotations (but also performs actions like 1+3 within it, and if you do a list like [1, 4, 2] it wont capture the weird space, and also always single quotes for everything even if you do repr(“hiello”)

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

abs()

A

returns absolute value of smth, either in or float or 0 or 1 when used on a boolean, part of standard python (no import needed)

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

ord()

A

standard python, converts string input to integer equivalent in unicode code

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

chr()

A

standard python, converts to single letter string from unicode code input

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

len()

A

standard python, returns length of any iterable data sequence (tuple, string, list)

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

del

A

keyword in standard python, deletes variables and elements of mutable data sequences, alterring the sequence itself (deletes parts of lists if you want it to and lessens length by 1 every time)

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

list()

A

standard python, typecasts something iterable to a list (does not work on floats or ints or booleans) (tuples and strings work though)

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

shuffle()

A

random module, randomly organizes items in data sequence. original object is mutated, DOES NOT CREATE NEW OBJECT
shuffle(x)

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

in

A

standard python keyword, returns boolean True or False if x is found anywhere in data sequence y (does not work on ints or floats or bools) (works on tuples and strings)

x in y = True or False

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

max() and min()

A

standard python, returns highest and lowest value in data sequence (even works to compare booleans and strings though you prob dont need that)

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

sum()

A

standard python, sums numbers in list (works on everything BUT strings)

sum(x)

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

mean()

A

statistics class, CANNOT be used on strings, returns average of data sequence elements

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

median()

A

statistics class, can be used on strings, returns middlemost element of data sequence

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

mode()

A

statistics class, can be used on strings, returns most common element of data sequence

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

multimode()

A

statistics class, mode but returns list and list can contain multiple “most common elements” of any data sequence

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

reverse()

A

list.reverse()
ONLY WORKS ON MUTABLE DATA SEQUENCE TYPES
reverses all elements in sequence

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

append

A

list.append(x)

adds ONE item to end of MUTABLE data sequence

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

pop

A

x.pop(i)

removes item at INDEX i from MUTABLE sequence x, UNLIKE OTHER SEQUENCE METHODS returns item removed

no index = defaults to i = -1, or last item in the list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
insert
x.insert(2, y) inserts y into x at index 2 of MUTABLE data sequence DOES NOT DELETE PREVIOUS ITEM AT THAT INDEX
26
extend
x.extend([y]) adds list y's elements to end of MUTABLE sequence x append would have just added a nested list
27
count
list.count(x) returns the number of occurrences of x in a list (works on all data sequences)
28
index
x.index(y) returns the index of y within x (works on all data sequences)
29
remove
x.remove(y) removes item y in x (NOT index location), works on MUTABLE data sequence
30
clear
x.clear() turns mutable sequence x into empty list
31
sort
ONLY WORKS ON LISTS list.sort() sorts list by ascending order (by default), or by descending if reverse flag set to true sorts list IN PLACE, does not return anything ex. numlist.sort(reverse=True)
31
sorted
sorted(numlist) RETURNS sorted list, does not change list itself works on any iterable
31
range
range(n) or range(number included, n) goes from number included to n-1, creating object of type range creates ITERATOR object one by one to n-1 to complete the whole iterator range(x, y, z) goes from x to y-1 in steps of z, and steps can also be negative just like slices of strings
32
iter
iter(x) determines whether input can be iterated through, as with a list or a variable set to equal range(n)
33
next
next(x) returns next value in iterator, first call will return the lowest number in the iterator by default (ex. next(range(n)) = 0)
34
enumerate
returns the index and the item itself of a data sequence in that specific order, can be used with two iterators in a for loop to get both as separate or only one iterator to be assigned a tuple pair (index, item) index, item = enumerate(x)
35
choice
choice(data sequence) selects random element
36
difference between +=, append, and extend for adding tuples?
+= and extend only add the values to the end, whereas append adds the actual tuple
37
set function
set(x) returns a list with only one of each instance
38
id
id(x) returns memory location variable or value points to/is stored in respectively
39
copy
x.copy() returns deep copy of list???
40
capitalize
x.capitalize() returns string with first letter capitalized
41
title
x.title() returns string with first and all words separated by space to be capital letters
42
swapcase
x.swapcase() returns opposite case string ("hELLO" ---> "Hello")
43
strip
x.strip() removes leading and trailing (but not middle) spaces
44
lstrip
x.lstrip() returns string w/o left or leading spaces
45
rstrip
x.rstrip() returns string w/o right or trailing spaces
46
center, ljust, rjust
x.function(y, char) y = amnt of spaces char = fill character (automatically spaces) returns centered, left justified , and right justified strings respectively if odd, one extra trailing space/character is addded
47
zfill
x.zfill(num) num = amnt of 0's adds a bunch of leading zeroes requires argument
48
join
char.join(iterable) iterable = iterable like a list char = the intended space character/string (cant be number or boolean)
49
split
x.split(separator, maxsplit=) splits string into list of terms separated by separator separator is not included in list if delimiter is not a space, consecutive delimiters are treated as empty strings in the returned string maxsplit = amount of splits desired (1 split = 2 components)
50
rsplit
same as split but from the right, useful when maxsplit is specified
51
splitlines
same as split but takes newlines as delimiters
52
partition
x.partition(separator) returns a tuple with 3 parts: the string left of the separator, the separator, and to the right of the separator works on 1st instance of separator left, seperator, right = x.partition(seperator)
53
rpartition
partition but starts at instance of partition to the right/last instance
54
find
x.find(inside) returns index of first instance but returns -1 not error when not found
55
rfind and rindex
find and index but from the right
56
replace
x.replace(thing, replacement) x.replace(thing, replacement, # of times thing should be replaced) replaces
57
startswith and endswith
obvi
58
isalpha
x.isalpha() True if all alphabetic chars, if not or empty = False
59
isalnum
x.isalnum() True if chars are alphanumeric false if not
60
isdigit
x.isdigit()
61
ascii_uppercase, ascii_lowercase, ascii_letters, digits
constants of string module: 1. uppercase alphabet 2. lowercase alphabet 3. lower + upper alphabets concatenated 4. all digits 0123456789
62
capitalize
x.capitalize() capitalizes just the first letter in the string, even if its a space
63
array()
64
dtype
dtype = and myarray.dtype (no parenthesis)
65
shape size ndim
no parenthesis for any, no np dot thingy
66
arange
np.arange(start, end (uninclusive), steps)
67
linspace
np.linespace(start, end, amount of linearly spaced points between) np.linespace(start, end (inclusive), amount of linearly spaced points between, dtype=int)
68
vstack
np.vstack((array1, array2)), stacks vertically, takes single tuple argument
69
hstack
np.hstack((array1, array2)) stacks horizontally (same row), takes single tuple argument
70
zeros ones full empty
np.zeros((# of arrays, rows of arrays, cols of arrays), dtype=whatevs) np.zeros((rows, cols)) np.zeroes(cols) np.ones() ^same as above np.full((# of arrays, rows of arrays, cols of arrays), number to put in array, dtype=whatevs) of arrays part can be removed https://numpy.org/doc/stable/reference/generated/numpy.zeros.html
71
default rng
np.random.default_rng()
72
random
np.random.default_rng().random(x)
73
integers
np.random.default_rng().integers(start, end, cols) np.random.default_rng().integers(start, end, (rows, cols)
74
logical indexing
flattens array and returns as true/false to the given condition m1d = np.arange(12) print(m1d) log = m1d < 10 print(log) m1d[log] ^indexes, returning: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) if print(m1d[log] is called, [0 1 2 3 4 5 6 7 8 9]
75
reshape
x.reshape(shape)
76
transpose
x.T swaps rows and columns
77
ravel
x.ravel() returns flattened
78
sum vs. np.sum
np.sum returns a single value
79
80