Untitled Deck Flashcards

(50 cards)

1
Q

snake_case is used for

A

variables and functions

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

core types

A

can be checked with method type()

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

extend()

A

can concatenate two lists;
list1.extend(list2)

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

identity operators

A

check for types;
is / is not

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

dictionaries

A

unordered and mutable

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

tuples

A

ordered but immutable, allowing duplicates. Should be used for values that will not change.

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

count()

A

count occurrences of something;
item.count(x)

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

index()

A

returns position of the first instance of that value;
item.index(x)

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

floor division

A

rounds down if the result is a decimal

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

list comprehensions

A

listname = [(process) for x in range(y)];
outputs the result of the process over the range

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

list slicing

A

list[starting index, ending index + 1];
excludes last number

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

dictionary access / assignment

A

my_dict[‘key’] = value

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

continue

A

continue skips the current iteration and moves to the next if condition is/n’t met

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

break

A

exits the loop if the condition is/n’t met with no more iterations

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

class

A

a definition for a variable to act a certain way and comply with new functions

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

object

A

an instance of a class, following the rules of that class with unique data;
object = myClass(a1, a2…)

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

__init__

A

a constructor; automatically called when an object of a class is created.
initializes (confirms + stores) the unique attributes

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

inheritance

A

a subclass inherits properties and methods from an existing class; promotes code reuse;
class Animal: …
class Dog(Animal): …
both have function speak(self)

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

super()

A

within a subclass, super() calls methods from the superclass without adding them to the subclass.
often used in the __init__ method for the subclass to initialize attributes inherited from the superclass

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

encapsulation

A

the bundling of attributes and methods into a single unit and restricting direct access to come of the object’s components;
coupling attributes into a class to protect the integrity of the data

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

polymorphism

A

the ability of an object to take on many forms;
methods can be overwritten in subclasses with super().func()

22
Q

refactor

A

third step of TDD: clean up code after ensuring the tests pass

23
Q

atomic operations

A

performed as a single, uninterruptible step;
arithmetic, variable assignment, branching statements.jumps,

24
Q

all dictionary operations are

A

of O(1) time complexity

25
adding and removing items from sets
O(1)
26
list indexing, adding to and popping from lists are
O(1) time complexity
27
list operations at specific indexes
O(n-i) time complexity
28
searching for x in a list
O(n) time complexity
29
list splicing
O(b - a)
30
adding lists
O(n1 + n2)
31
sorting a list
O(n log n)
32
order of time complexities:
O(1), O(log n), O(n), O(n log n), O(n^2), O(n^x), O(2^n), O(n!)
33
methods for reducing time complexity
eliminate unnecessary repeated work, use sets / dictionaries for faster lookups, remove slow parts of the algorithm
34
a loop runs while n > 1, and n // 2 after every iteration
O(log n)
35
nested loops iterating over the same variable
O(n^x)
36
nested loops iterating over different variables
O(n * m)
37
max and min
O(n), if unsorted
38
push(item)
add to top of stack
39
pop()
removes from top of stack
40
peek()
views next removable item without removing
41
enqueue(item)
add to back of queue
42
dequeue()
removes from front of queue
43
implementing stack
list wrapper; python list, append + pop
44
implementing queue
track front with head index; dequeue increments head; cleanup when head > len/2
45
.capitalize()
capitalizes first letter of a string
46
if a subclass has new variables
init separately under def__init__; inherit other variables with super().__init__(var)
47
if a subclass has a similar function
inherit base functionality with super.function(), adding extra conditionals before or after to match
48
unittest formula:
import unittest class TestClassName(unittest.TestCase): def test_func(p1, p2...): # define values + run process self.assertEqual(expected result of process) unittest.main()
49
__str__
returns a readable string representation of an object;
50
.join()
joins iterables by a separator: "separator".join(obj)