Skip to content

Instantly share code, notes, and snippets.

@xuru
Created October 29, 2013 14:09
Show Gist options
  • Select an option

  • Save xuru/7215356 to your computer and use it in GitHub Desktop.

Select an option

Save xuru/7215356 to your computer and use it in GitHub Desktop.
Some questions to ask potential interviewers to test there knowledge of python. Senior to principle level.
Re-write the following to improve performance (assume the lists below could number into the thousands of elements).
list1 = [{'a': 1, 'b': 2}, {'c': 3, 'd': 4}, {'e': 5, 'f': 6}]
list2 = [{'e': 5, 'f': 6}, {'g': 7, 'h': 8}, {'i': 9, 'j': 10}]
common = []
for entry in list1:
if entry in list2:
common.append(entry)
What will be returned from the following list comprehension?
[a - b for (a,b) in zip((1,2,3), (1,2,3))]
Although not syntactically incorrect, what is wrong with the following code?
def foo(x=[]):
x.append(1)
print x
What does the following print?
a = [1,2,3,4,5]
print a[::-1]
What are the special class methods __enter__ and __exit__ used for?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment