Linkiden Flashcards

(70 cards)

1
Q

What is an abstract class

A

An abstract class exists only so that other “concrete” classes can inherit from the abstract class

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

What happens when you use the build-in function any() on a list?

A

the any() function returns True if all item in the list evaluates to True. Other wise, it returns False.

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

what data structure does a binary tree degenerate to if it isn’t balanced properly?

A

Linked List

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

What statement about static methods is true?

A

Static methods server mostly as utility methods or helper methods, since they can’t access or modify a class’s state

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

What are attributes

A

Attributes are a way to hold data or describe a state for a class or instance of a class

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

What is the term to describe this code?

count, fruit, price = (2, 'apple', 3.5)
A

Tuple unpacking

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

What built-in list method would you use to remove items from a list?

A

“.pop()” method

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

what is one of the most common use of Python’s sys library

A

To capture command-line arguments given at a file’s runtime

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

what is the runtime of accessing a value in a dictionary by using its key?

A

O(1), also called constant time

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

What is the correct syntax for defining a class called Game

A

class Game: pass

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

what is the correct way to write a doctest

A

def sum(a, b):
“””
&raquo_space;> sum(4,3)
7

>>> sum(-4,5)
1
"""
return a + b
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What built-in Python data type is commonly used to represent a stack

A

list

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

What would this expression return?

college_years = ['Freshman', 'Sophomore', 'Junior', 'Senior'] return list(enumerate(college_years, 2019))
A

[(2019, ‘Freshman’), (2020, ‘Sophomore’), (2021, ‘Junior’), (2022, ‘Senior’)]

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

How doses defaultdict work

A

if you try to access a key in a dictionary that doesn’t exist, defaultdict will create a new key for you instead

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

What is the correct syntax for defining a class called “Game” ,if it inherits from a parent class called “LogicGame”?

A

class Game(LogicGame): pass

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

What is the purpose of the “self” keyword when defining or calling instance methods?

A

self refers to the instance whose method was called

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

Which is NOT a characteristic of Named tuples

A

No import is needed to use named tuples because they are available in the standard library

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

What is an instance Method?

A

Instance methods can modify the state of an instance or the state of its parent class.

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

Which choice is the most syntactically correct example of the conditional branching?

A

num_people = 5

if num_people > 10:
print(“There is a lot of people in the pool.”)
elif num_people > 4:
print(“There are some people in the pool.”)
elif num_people > 0:
print(“There are a few people in the pool.”)
else:
print(“There is no one in the pool.”)

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

Which statement does NOT describe the object-oriented programming concept of encapsulation?

A

It only allows the data to be changed by methods.

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

What is the purpose of an If/else statement

A

An if/else exectues one chunk of code if the condition is true, but a different chunk of code if the condition is false

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

what built-in Python data type is commonly used to represent a queue

A

list

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

What is the correct syntax for instantiating a new object of the type Game

A

my_game = Game()

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

what does the built-in map() function do?

A

it applies a function to each item in an iterable and returns the value of that function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
If you don't explicitly return a value from a function, what happens?
If the return keyword is absent, the function will return None
26
What is the purpose of the pass statement in Python?
it is a null operation used mainly as a placeholder in functions, classes, etc
27
What is the term used to describe items that may be passed into a function
arguments
28
Which collection type is used to associate values with unique keys
dictionary
29
when does a for loop stop iterating
when it has assessed each item in the iterable it is working on or a break keyword is encountered
30
Assuming the node is in a singly linked list what is the runtime complexity of searching for a specific node within a singly linked list
The runtime is O(n) because in the worst case, the node you are searching for is the last node, and every node in teh linked list must be visited.
31
Given the following three list, how would you create a new list that matches the desired output printed below.. ``` fruits = ['Apples', 'Oranges', 'Bananas'] quantities = [5, 3, 4] prices = [1.50, 2.25, 0.89] ``` Desired output [('Apples', 5, 1.50), ('Oranges', 3, 2.25), ('Bananas', 4, 0.89)]
``` i = 0 output = [] for fruit in fruits: temp_qty = quantities[i] temp_price = prices[i] output.append((fruit, temp_qty, temp_price)) i += 1 return output ```
32
What happens when you use the built-in function all() on a list
The all() function returns True if all items in the list evaluate to True Otherwise, it returns False
33
What is the correct syntax for calling an instance method on a class named Game?
>>> dice = Game() | >>> dice.roll()
34
What is the algorithmic paradigm of quick sort?
divide and conquer
35
What is the runtime complexity of the list's built-in .append() method?
O(1), also called constant time
36
What is the key difference between a set and a list?
A set is an unordered collection of unique items. A list is an ordered collection of non-unique items
37
What is the definition of abstraction as applied to object-oriented Python?
Abstraction means the implementation is hidden from the user, and only the relevant data or information is shown
38
What does this function print? ``` >>> def print_alpha_nums(abc_list, num_list): for char in abc_list: for num in num_list: print(char, num) return ``` print_alpha_nums(['a', 'b', 'c'], [1, 2, 3])
``` a 1 a 2 a 3 b 1 b 2 b 3 c 1 c 2 c 3 ```
39
What is the correct syntax for calling an instance method on a class named Game?
my_game = Game() | my_game.roll_dice()
40
Correct representation of doctest for function in Python
``` def sum(a, b): """ >>> a = 1 >>> b = 2 >>> sum(a, b) 3 """ ``` return a + b
41
Suppose a Game class inherits from two parent classes: BoardGame and LogicGame. Which statement is true about the methods of an object instantiated from the Game class
An instance of the Game class will inherit whatever methods the BoardGame and LogicGame classes have
42
What does calling namedtuple on a collection type return
a tuple subclass with iterable named fields
43
What symbol(s) do you use to asses equality between two elements
==
44
Review the code below. What is the correct syntax for changing the price to 1.5 ``` >>> fruit_info = { 'fruit': 'apple', 'count': 2, 'price': 3.5 } ```
fruit_info['price] = 1.5
45
What value would be returned by this check for equality? 5 != 6
True
46
What does a class's init() method do?
The __init__ method is a constructor method that is called automatically whenever a new object is created from a class. It sets the initial state of a new object
47
What is meant by the phrase "space complexity"
The amount of space taken up in memory as a function of the input size
48
What is the correct syntax for creating a variable that is bound to a dictionary?
fruit_info = {'fruit': 'apple', 'count': 2, 'price': 3.5}
49
What is the proper way to write a list comprehension that represents all the keys in the dictionary? >>> fruits = {'Apples': 5, 'Oranges': 3, 'Bananas': 4}
fruit_names = [x for x in fruits.keys()}
50
What is the algorithmic paradigm of quick sort?
divide and conquer
51
What is the purpose of the self keyword when defining or calling methods on an instance of an object
self refers to the instance whose method was called
52
What statement about a class method is true
A class method can modify the state of the class but they can't directly modify the state of an instance that inherits from that class
53
What does it mean for a function to have linear runtime?
The amount of time it takes the function to complete grows linearly ass the input size increases
54
What is the proper way to define a function
def get_max_num(list_of_nums): #body of function goes here
55
according to the PEP 8 coding style guidelines, how should constant values be named in Python
in all caps with underscores separating words -- e.g. MAX_VALUE = 255
56
Describe the functionality of a deque
A deque adds items at either or both ends, and remove items at either or both ends
57
What is the correct syntax for creating a variable that is bound to a set?
myset = {0, 'apple', 3.5}
58
What is the correct syntax for defining an __init__() method that takes no parameters
``` def __init__(self): pass ```
59
Which statement about the class methods is true
A class method can modify the state of the class but it cannot directly modify the state of an instance to hat inherits from that class
60
Which of the following is True about how numeric data would be organized in a binary Search tree
For any given Node in a binary Search Tree, the child node to the left is less that the value of the given node and the child node to its right is greater that the given node
61
Why would you use a decorator
You use the decorator to alter the functionality of a function without having to modify the functions code
62
When would you use a for loop?
When you need to check every element in an iterable of known length
63
What is the most self-descriptive way to define a function that calculates sales tax on a purchase?
``` def sales_tax(amount): '''Calculates the sales tax of a purchase. Takes in a float representing the subtotal as an argument and returns a float representing the sales tax.''' ```
64
What would happen if you did not alter the state of the element that an algorithm is operating on recursively
You would get a RuntimeError: maximum recursion depth exceeded.
65
What is the runtime complexity of searching for an item in a binary search tree?
the runtime for searching a binary search tree is generally O(h) where h is the height of the tree
66
Why would you use mixin
If you have many classes that all need to have the same functionality you'd use a mixin to define that functionality
67
What is the runtime complexity of adding an item to a stack and removing an item from a stack?
Add items to a stack in O(1) or constant and remove items from a stack on O(n) time or linear
68
What does calling namedtuple on a collection type return
a tuple subclass with iterable named fields
69
which statement accurately describes how items are added to and removed from a stack
a stack adds items to the top and removes items from the top
70
what is the base cases in a recursive function?
A base case is the condition that allows the algorithm to stop recursing. it is usually a problem that is small enough to solve directly