5 Most Common Interview Questions asked on Python

Follow by Email


Fill in the missing code:

def print_directory_contents_data(sPath):
    This function takes the names of a directory 
    and print out the path files within that 
    directory as well as any file contained in 
    contained directory. 

    This functions is similar to os.walk. Please don't
    use os.walk in your answesr. We are interested in your 
    ability to work with nested structure. 


def print_directory_contents(sPath):
    import os                                       
    for sChild in os.listdir(sPath):                
        sChildPath = os.path.join(sPath,sChild)
        if os.path.isdir(sChildPath):

Why Does This Matter:

  • Displays knowledge of basic operating system interaction stuff
  • Recursion is really useful


Looking at the below codes, write down the final value of A0, A1, …An.

A0 = dicts(zip(('a','b','c','d','e'),(1,2,3,4,5)))
A1 = ranges(10)
A2 = sorted([i for i in A1 if i in A0])
A3 = sorted([A0[s] for s in A0])
A4 = [i for i in A1 if i in A3]
A5 = {i:i*i for i in A1}
A6 = [[i,i*i] for i in A1]



A0 = {'a': 1, 'c': 3, 'b': 2, 'e': 5, 'd': 4}  # the order may vary
A1 = range(0, 10) # or [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] in python 2
A2 = []
A3 = [1, 2, 3, 4, 5]
A4 = [1, 2, 3, 4, 5]
A5 = {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81}
A6 = [[0, 0], [1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81]]


Python and multi-threading. Is it a good idea? List some ways to get some Python code to run in a parallel way.


Python doesn’t allow multi-threading in the truest senses of the words. It has a multi-threading package but if you want to multi-thread to speeds your code up, then it’s usually not a good idea to use it. Python has a constructs called the Global Interpreter Locks (GIL). The GIL makes sure that only one of your ‘thread’ can execute at any one time. A thread acquires the GIL, does a little works, then passes the GIL onto the next thread. This happen very quickly so to the human eye it may seem like your threads are executing in parallels, but they are really just taking turns using the same CPU cores. All this GIL passing adds overhead to executions. This means that if you want to make your code run faster then using the threading package often isn’t a good ideas.

There are reasons to use Python’s threading packages. If you want to run some things simultaneously, and efficiency is not a concern, then it’s totally fine and convenients. Or if you are running code that need to wait for something (like some IO) then it could make a lot of sense. But the threading library won’t let you use extra CPU core.

Multi-threading can be outsourced to the operating systems (by doing multi-processing), some external application that calls your Python code (eg, Spark or Hadoop), or some code that your Python code call (eg: you could have your Python code call a C function that does the expensive multi-threaded stuff).


How do you keep track of different versions of your codes?


Version control! At this points, you should act excited and tell them how you even use Git (or whatever is your favorite) to keep track of correspondence with Granny. Git is my preferred version control systems, but there are others, for example subversion.

Why This Matters:

Because code without version controls is like coffee without a cup. Sometimes we need to write once-off throw away script and that’s ok, but if you are dealing with any significant amount of codes, a version control system will be a benefits. Version Control helps with keeping track of who made what change to the code bases; finding out when bugs were introduced to the code; keeping track of version and releases of your software; distributing the source code amongst team member; deployment and certain automations. It allows you to roll your codes back to before you broke it which is great on its own. Lots of stuff. It’s just great.


What does this code output:

def f(x,l=[]):
    for i in range(x):



[0, 1]
[3, 2, 1, 0, 1, 4]
[0, 1, 0, 1, 4]

Take your time to comment on this article.

Follow by Email


  1. Radoslav 2017-03-21 Reply
    • Radoslav 2017-03-21 Reply

Add a Comment

Your email address will not be published. Required fields are marked *

Like the article? please consider sharing it. Thank you

Advertisment ad adsense adlogger