> masteringswe_

Python - Coding Interviews

Cards from Python - Coding Interviews

Questions

01Define an empty list, my_list
coding
02Add 1 to the end of list, my_list
coding
03Remove and get the last element in list, my_list
coding
04Remove and get the first element in list, my_list
coding
05Reverse list, my_list, in place
coding
06Sort list, my_list, in ascending order
codinglocked
Subscribe to unlock
07Sort list, my_list, in descending order
codinglocked
Subscribe to unlock
08Sort list, my_list, using a custom key
codinglocked
Subscribe to unlock
09Combine list, my_list, with list, another_list, and assign the result back to my_list
codinglocked
Subscribe to unlock
10Mutate list, my_list, by adding all elements from list, another_list, to the end of it
codinglocked
Subscribe to unlock
11Get the first index of value in list, my_list and throw an error if it does not exist
codinglocked
Subscribe to unlock
12Create a shallow copy of list, my_list
codinglocked
Subscribe to unlock
13Create a slice from index 2 up to, but not including, index 5 from list, my_list
codinglocked
Subscribe to unlock
14Check whether value exists in list, my_list
codinglocked
Subscribe to unlock
15Define an empty set, my_set
codinglocked
Subscribe to unlock
16Add 1 to set, my_set
codinglocked
Subscribe to unlock
17Check whether value exists in set, my_set
codinglocked
Subscribe to unlock
18Remove 1 from set, my_set without throwing an error if it does not exist
codinglocked
Subscribe to unlock
19Remove 1 from set, my_set and throw an error if it does not exist
codinglocked
Subscribe to unlock
20Get the number of elements in set, my_set
codinglocked
Subscribe to unlock
21Get the number of elements in list, my_list
codinglocked
Subscribe to unlock
22Define an empty dictionary, my_map
codinglocked
Subscribe to unlock
23Insert key "age" with value 20 into dictionary, my_map
codinglocked
Subscribe to unlock
24Check whether key "age" exists in dictionary, my_map
codinglocked
Subscribe to unlock
25Get the value associated with key "age" from dictionary, my_map, using direct access that returns None if missing
codinglocked
Subscribe to unlock
26Get the value associated with key "age" from dictionary, my_map, using direct access
codinglocked
Subscribe to unlock
27Delete key "age" from dictionary, my_map
codinglocked
Subscribe to unlock
28Remove all elements from dictionary, my_map
codinglocked
Subscribe to unlock
29Return the number of key-value pairs in dictionary, my_map
codinglocked
Subscribe to unlock
30Create a list of all keys and values from dictionary, my_map
codinglocked
Subscribe to unlock
31Iterate over all key-value pairs in dictionary, my_map
codinglocked
Subscribe to unlock
32Get the first inserted key from dictionary, my_map
codinglocked
Subscribe to unlock
33Create a list of length "length" where each element is the same reference default_vals
codinglocked
Subscribe to unlock
34Create a list of length "length" where each element is a new object created by calling default_vals
codinglocked
Subscribe to unlock
35Iterate over all keys in dictionary, my_map
codinglocked
Subscribe to unlock
36Iterate over all values in dictionary, my_map
codinglocked
Subscribe to unlock
37Create a shallow copy of dictionary, my_map
codinglocked
Subscribe to unlock
38Check whether value exists in dictionary, my_map, as a value in a key-value pair
codinglocked
Subscribe to unlock
39ordering of keys in dictionary
conceptuallocked
Subscribe to unlock
40Create a shallow copy of set, my_set
codinglocked
Subscribe to unlock
41Can you add data of different types into a dictionary, set, or list
conceptuallocked
Subscribe to unlock
42Concatenate the list of strings with a space in between each string in O(N) time
codinglocked
Subscribe to unlock
43Concatenate the two strings using an f-string with a space in between them
codinglocked
Subscribe to unlock
44Concatenate the two strings using the + operator with a space in between them
codinglocked
Subscribe to unlock
45Assign the string "myString" to variable s
codinglocked
Subscribe to unlock
46Get the Unicode code point of character "s"
codinglocked
Subscribe to unlock
47Get the corresponding character from a Unicode value, unicode_value
codinglocked
Subscribe to unlock
48Convert string s to all lowercase characters and assign it back to s
codinglocked
Subscribe to unlock
49Convert string s to all uppercase characters and assign it back to s
codinglocked
Subscribe to unlock
50Import the heapq module
codinglocked
Subscribe to unlock
51Insert value into heap (min heap)
codinglocked
Subscribe to unlock
52Insert value into heap to simulate a max-heap by negating the value
codinglocked
Subscribe to unlock
53Remove and get the root element from heap
codinglocked
Subscribe to unlock
54Get (peek) the root element of heap without removing it
codinglocked
Subscribe to unlock
55Convert list, heap, into a heapq min-heap in-place
codinglocked
Subscribe to unlock
56Define an empty heapq min-heap, heap.
codinglocked
Subscribe to unlock
57Define class Person with constructor taking in name and age
codinglocked
Subscribe to unlock
58Create an instance of the given class
codinglocked
Subscribe to unlock
59Implement a typical map function
codinglocked
Subscribe to unlock
60Define incrementing lambda functions
codinglocked
Subscribe to unlock
61Define a simple lambda function and invoke it
codinglocked
Subscribe to unlock
62Define class Dog that inherits from Animal and invokes parent method
codinglocked
Subscribe to unlock
63Define class Dog that inherits from Animal without overriding parent method
codinglocked
Subscribe to unlock
64Define a method and invoke it
codinglocked
Subscribe to unlock
65Basic arithmetic operators
codinglocked
Subscribe to unlock
66Advanced arithmetic operators
codinglocked
Subscribe to unlock
67Increment decrement shorthand
codinglocked
Subscribe to unlock
68Update global variable from within function
codinglocked
Subscribe to unlock
69What is the global keyword
codinglocked
Subscribe to unlock
70Global output 95
conceptuallocked
Subscribe to unlock
71Global output 96
conceptuallocked
Subscribe to unlock
72Global output 97
conceptuallocked
Subscribe to unlock
73Global output 98
conceptuallocked
Subscribe to unlock
74Global output 99
conceptuallocked
Subscribe to unlock
75Global output 100
conceptuallocked
Subscribe to unlock
76Global output 101
conceptuallocked
Subscribe to unlock
77Global output 102
conceptuallocked
Subscribe to unlock
78Global output 103
conceptuallocked
Subscribe to unlock
79What is the nonlocal keyword
conceptuallocked
Subscribe to unlock
80Nonlocal output 105
conceptuallocked
Subscribe to unlock
81Nonlocal output 106
conceptuallocked
Subscribe to unlock
82Nonlocal output 107
conceptuallocked
Subscribe to unlock
83Nonlocal output 108
conceptuallocked
Subscribe to unlock
84Pass by output 109
conceptuallocked
Subscribe to unlock
85Pass by output 110
conceptuallocked
Subscribe to unlock
86Is python pass by reference or pass by value
conceptuallocked
Subscribe to unlock
87Iterate through list, my_list using in, range, and enumerate
codinglocked
Subscribe to unlock
88Create a list of all key-value items from dictionary, my_map
codinglocked
Subscribe to unlock
89Iterate through set, my_set, using in and enumerate
codinglocked
Subscribe to unlock
90Write a while loop that breaks after 10 iterations
codinglocked
Subscribe to unlock
91Get the 3rd element in list, my_list
codinglocked
Subscribe to unlock
92Get conditional of whether 3 is not in list, my_list
codinglocked
Subscribe to unlock
93Get conditional of whether 3 is not in set, my_set
codinglocked
Subscribe to unlock
94Check whether key "age" does not exist in dictionary, my_map
codinglocked
Subscribe to unlock
95Get index of alphabet letter
codinglocked
Subscribe to unlock
96Define heap using custom priority
codinglocked
Subscribe to unlock
97String output 122
conceptuallocked
Subscribe to unlock
98Write a range loop from 0 to 10 (non-inclusive)
codinglocked
Subscribe to unlock
99Write a range loop from 10 to 20 (non-inclusive)
codinglocked
Subscribe to unlock
100Write a range loop from 0 to 10 (non-inclusive) skipping every other index
codinglocked
Subscribe to unlock
101Round numbers down and up to nearest integer
codinglocked
Subscribe to unlock
102Get the min and max of numbers
codinglocked
Subscribe to unlock
103Get the absolute value of the number
codinglocked
Subscribe to unlock
104Get infinity and negative infinity
codinglocked
Subscribe to unlock
105Create a double-ended queue and execute append / pop operations
codinglocked
Subscribe to unlock
106Get the 0 index element from deque
codinglocked
Subscribe to unlock
107Get the square root of 49
codinglocked
Subscribe to unlock
108Implement binary search
codinglocked
Subscribe to unlock
109Implement depth first search
codinglocked
Subscribe to unlock
110Implement breadth first search
codinglocked
Subscribe to unlock
111Define a set, my_set, with elements
codinglocked
Subscribe to unlock
112Define dictionary, my_map, with elements
codinglocked
Subscribe to unlock
113Implement polymorphic dog behaviors functionally
codinglocked
Subscribe to unlock
114Implement polymorphic dog behaviors using OOD
codinglocked
Subscribe to unlock
115Use a built-in map function
codinglocked
Subscribe to unlock
116Use a built-in filter function
codinglocked
Subscribe to unlock
117Map with list comprehension
codinglocked
Subscribe to unlock
118Filter with list comprehension
codinglocked
Subscribe to unlock
119Create set using string
codinglocked
Subscribe to unlock
120Create a list using string
codinglocked
Subscribe to unlock
121Output 146
conceptuallocked
Subscribe to unlock
122Print ‘hi’ if and / or logic is truthful
codinglocked
Subscribe to unlock
123Get bitwise AND from binary numbers
codinglocked
Subscribe to unlock
124Check if bit i is turned on in binary number
codinglocked
Subscribe to unlock
125Shift all bits left by one position
codinglocked
Subscribe to unlock
126Get bitwise OR from binary numbers
codinglocked
Subscribe to unlock
127Turn on bit i in binary number
codinglocked
Subscribe to unlock
128Define an empty defaultdict, def_dict, defaulting to empty lists
codinglocked
Subscribe to unlock
129Define an empty defaultdict, def_dict, defaulting to 0
codinglocked
Subscribe to unlock
130Define an empty defaultdict, def_dict, defaulting to non-empty string
codinglocked
Subscribe to unlock
131Fix == operation
codinglocked
Subscribe to unlock
132Allow object to be in set
codinglocked
Subscribe to unlock