Untitled Deck Flashcards

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
Q

adding and removing items from sets

26
Q

list indexing, adding to and popping from lists are

A

O(1) time complexity

27
Q

list operations at specific indexes

A

O(n-i) time complexity

28
Q

searching for x in a list

A

O(n) time complexity

29
Q

list splicing

30
Q

adding lists

A

O(n1 + n2)

31
Q

sorting a list

A

O(n log n)

32
Q

order of time complexities:

A

O(1), O(log n), O(n), O(n log n), O(n^2), O(n^x), O(2^n), O(n!)

33
Q

methods for reducing time complexity

A

eliminate unnecessary repeated work, use sets / dictionaries for faster lookups, remove slow parts of the algorithm

34
Q

a loop runs while n > 1, and n // 2 after every iteration

35
Q

nested loops iterating over the same variable

36
Q

nested loops iterating over different variables

37
Q

max and min

A

O(n), if unsorted

38
Q

push(item)

A

add to top of stack

39
Q

pop()

A

removes from top of stack

40
Q

peek()

A

views next removable item without removing

41
Q

enqueue(item)

A

add to back of queue

42
Q

dequeue()

A

removes from front of queue

43
Q

implementing stack

A

list wrapper;
python list, append + pop

44
Q

implementing queue

A

track front with head index; dequeue increments head; cleanup when head > len/2

45
Q

.capitalize()

A

capitalizes first letter of a string

46
Q

if a subclass has new variables

A

init separately under def__init__;
inherit other variables with super().__init__(var)

47
Q

if a subclass has a similar function

A

inherit base functionality with super.function(), adding extra conditionals before or after to match

48
Q

unittest formula:

A

import unittest
class TestClassName(unittest.TestCase):
def test_func(p1, p2…):
# define values + run process
self.assertEqual(expected result of process)

unittest.main()

49
Q

__str__

A

returns a readable string representation of an object;

50
Q

.join()

A

joins iterables by a separator:

“separator”.join(obj)