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
Q

insert

A

x.insert(2, y)

inserts y into x at index 2 of MUTABLE data sequence
DOES NOT DELETE PREVIOUS ITEM AT THAT INDEX

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

extend

A

x.extend([y])
adds list y’s elements to end of MUTABLE sequence x

append would have just added a nested list

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

count

A

list.count(x)
returns the number of occurrences of x in a list (works on all data sequences)

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

index

A

x.index(y)
returns the index of y within x (works on all data sequences)

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

remove

A

x.remove(y)
removes item y in x (NOT index location), works on MUTABLE data sequence

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

clear

A

x.clear()

turns mutable sequence x into empty list

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

sort

A

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)

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

sorted

A

sorted(numlist)

RETURNS sorted list, does not change list itself

works on any iterable

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

range

A

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
Q

iter

A

iter(x)
determines whether input can be iterated through, as with a list or a variable set to equal range(n)

33
Q

next

A

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
Q

enumerate

A

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
Q

choice

A

choice(data sequence)
selects random element

36
Q

difference between +=, append, and extend for adding tuples?

A

+= and extend only add the values to the end, whereas append adds the actual tuple

37
Q

set function

A

set(x)

returns a list with only one of each instance

38
Q

id

A

id(x)
returns memory location variable or value points to/is stored in respectively

39
Q

copy

A

x.copy()

returns deep copy of list???

40
Q

capitalize

A

x.capitalize()
returns string with first letter capitalized

41
Q

title

A

x.title()
returns string with first and all words separated by space to be capital letters

42
Q

swapcase

A

x.swapcase()
returns opposite case string (“hELLO” —> “Hello”)

43
Q

strip

A

x.strip()
removes leading and trailing (but not middle) spaces

44
Q

lstrip

A

x.lstrip()
returns string w/o left or leading spaces

45
Q

rstrip

A

x.rstrip()
returns string w/o right or trailing spaces

46
Q

center, ljust, rjust

A

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
Q

zfill

A

x.zfill(num)
num = amnt of 0’s
adds a bunch of leading zeroes
requires argument

48
Q

join

A

char.join(iterable)
iterable = iterable like a list
char = the intended space character/string (cant be number or boolean)

49
Q

split

A

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
Q

rsplit

A

same as split but from the right, useful when maxsplit is specified

51
Q

splitlines

A

same as split but takes newlines as delimiters

52
Q

partition

A

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
Q

rpartition

A

partition but starts at instance of partition to the right/last instance

54
Q

find

A

x.find(inside)
returns index of first instance but returns -1 not error when not found

55
Q

rfind and rindex

A

find and index but from the right

56
Q

replace

A

x.replace(thing, replacement)
x.replace(thing, replacement, # of times thing should be replaced)

replaces

57
Q

startswith and endswith

A

obvi

58
Q

isalpha

A

x.isalpha()
True if all alphabetic chars, if not or empty = False

59
Q

isalnum

A

x.isalnum()
True if chars are alphanumeric false if not

60
Q

isdigit

A

x.isdigit()

61
Q

ascii_uppercase, ascii_lowercase, ascii_letters, digits

A

constants of string module:
1. uppercase alphabet
2. lowercase alphabet
3. lower + upper alphabets concatenated
4. all digits 0123456789

62
Q

capitalize

A

x.capitalize()
capitalizes just the first letter in the string, even if its a space

63
Q

array()

A
64
Q

dtype

A

dtype = and myarray.dtype (no parenthesis)

65
Q

shape
size
ndim

A

no parenthesis for any, no np dot thingy

66
Q

arange

A

np.arange(start, end (uninclusive), steps)

67
Q

linspace

A

np.linespace(start, end, amount of linearly spaced points between)
np.linespace(start, end (inclusive), amount of linearly spaced points between, dtype=int)

68
Q

vstack

A

np.vstack((array1, array2)), stacks vertically, takes single tuple argument

69
Q

hstack

A

np.hstack((array1, array2)) stacks horizontally (same row), takes single tuple argument

70
Q

zeros
ones
full
empty

A

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
Q

default rng

A

np.random.default_rng()

72
Q

random

A

np.random.default_rng().random(x)

73
Q

integers

A

np.random.default_rng().integers(start, end, cols)
np.random.default_rng().integers(start, end, (rows, cols)

74
Q

logical indexing

A

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
Q

reshape

A

x.reshape(shape)

76
Q

transpose

A

x.T
swaps rows and columns

77
Q

ravel

A

x.ravel()
returns flattened

78
Q

sum vs. np.sum

A

np.sum returns a single value

79
Q
A
80
Q
A