Python developer Interview Questions | Glassdoor

# Python developer Interview Questions

"Python developers are responsible for developing code to build products using the python programming language. In an interview context, expect to be quizzed on your technical skills through different kinds of computing problems or brainteasers. The specific questions you are asked will depend on what type of programming position you are looking for. Try researching a specific discipline such as web development, application development, or system development."

## Top Interview Questions

Sort: RelevancePopular Date

Apr 22, 2016
 Write a function to return the nth fibonacci number. The first two can be assumed to be 1 and 1. The third and fourth are then calculated to be 2 and 3.3 AnswersThe matlab example sets N = 12 (the 12th fab. number) which happens to be 144. N = 12; f = ones(N,1); for i = 3:N; f(i) = f(i-1) + f(i-2); end; f(end)fib = {1:1, 2:1} def calc_fib(n): if n in fib.keys(): return fib[n] else: fib[n]=calc_fib(n-1)+calc_fib(n-2) return fib[n] print(calc_fib(9))remember how to approximate as N is large

Apr 22, 2016
 How would you write a program to move inside a square spiral? Start at the upper left corner of the square and walk its edges clockwise. Just before re-approaching the upper left corner, spiral into the square instead, ultimately arriving at the center of the square.2 Answersdef spiral(mat): mat = np.array(mat) arr = [] if mat.shape == (1, 1): arr.append(mat) return arr else: arr.extend(mat[0, :]) arr.extend(spiral(np.rot90(mat[1:, :]))) return arrdef print_spiral(matrix): print_spiral_help(matrix, 0, 0, 0, len(matrix) - 1, len(matrix) - 1) def print_spiral_help(matrix, dir, top, left, right, bot): if left > right or top > bot: return # top if dir == 0: for i in range(left, right + 1): print matrix[top][i], print_spiral_help(matrix, 1, top + 1, left, right, bot) # Right elif dir == 1: for i in range(top, bot + 1): print matrix[i][right], print_spiral_help(matrix, 3, top, left, right - 1, bot) # Left elif dir == 2: for i in range(bot, top - 1, -1): print matrix[i][left], print_spiral_help(matrix, 0, top, left + 1, right, bot) # Bottom elif dir == 3: for i in range(right, left - 1, -1): print matrix[bot][i], print_spiral_help(matrix, 2, top, left, right, bot - 1)

Apr 22, 2016
 For the years 1901 to 2000, count the total number of Sundays that fell on the first of a month.2 AnswersTwo lines of code in matlab: Answer is 171 sundays fall on the first day of the month from 1 Jan 1901 to 31 Dec 2000 dt = datenum(1901,1,1):datenum(2001,1,1)-1; sum(day(dt(weekday(dt) == 1)) == 1)import datetime c = 0 for y in range(1901,2001): for m in range(1,13): d = datetime.datetime(y,m,1) if d.weekday() == 6: c += 1 print('Number of Sundays: ',c)

### Developer (Python) at Driver Group was asked...

Aug 9, 2016
 Given a set of 50 unique DNA segments under 1000 characters that is guaranteed to overlap into one single segment, write a program that will align them.1 AnswerI started off by building off one one end and then switching to the other. I searched for matching segments of a certain length and then tested for the overlap as I went along

Jun 24, 2015
 How would you triage and go about fixing infrastructure problems? Giving an input file, get the number of lines matching a specific piece of text using bash scripting. Give the percentage of lines in the file that match that string. 3 Answers1.) I said hard to tell because that is a very vague question. 2.) Use grep and awk and wc. 3.) Use the above plus "bc" to calculate percentage.for: 2.) Use grep and awk and wc. I believe grep + uniq + wc would be better and simpler, right?for: 2.) Use grep and awk and wc. 'grep -c' is enough

Apr 22, 2016
 Given a very long string composed of numbers as characters, find the four character substring that has the largest multiple. For example, given the string "809723", the two char substring with the largest multiple is "97", having a multiple 9*7 = 63.4 Answersmax([functools.reduce(operator.mul, data[i-4:i]) for i in data if i > 3])max([functools.reduce(operator.mul, data[i-4:i]) for (i, e) in enumerate(data) if e > 3])Show More Responsesdef largest_2str_multipler(a): l = len(a) m = int(a)*int(a) for x in range(1,l-1): if m < int(a[x])*int(a[x+1]): m = int(a[x])*int(a[x+1]) return m One or more comments have been removed. Please see our Community Guidelines or Terms of Service for more information.

### Full Stack Python Developer at SendHub was asked...

Feb 25, 2015
 work history stuff then a long comprehensive test to complete in 48 hours3 AnswersUploaded code to a github for reviewSorry for the slight delay. Wanted to try and get some more concrete feedback for you before responding again. It's difficult not to, but please try not to take the no feedback ''turn down'' email personally. It's SendHub's and a lot of other startups standard process with test feedback because of it being confidential (I've yet to understand why, but it's the case with a lot of them :)) . Ash really liked you though, said you seem really nice and very sharp. With your test it was a case of attention to detail. They said it was good, but there were a few things that didn't make sense for them in terms of the way you were using Python. However (if this is any consolation) they really appreciate the extra effort you put in and said that no one has ever done that before. It certainly wasn't unnoticed and they were gracious about you doing that. To developupload, test and document in 3 hours.nice and sharp doesn't get you the job. I expect this company will run their engineers into the ground. I stand by my code.

Oct 15, 2017
 Hackerrank test: 1) Print Roman number equivalent for numbers 1-1000 2) Order a list of words appearing in a file by number of letters but maintain original order ("stable sorting") of words with same length 3) Implement a stack class with methods to do some specific operations mentioned in the question. Phone/Codepad interview: 1) Given a series of prices, find the one buy/sell trade pair which gives the maximum profit 2) Modification of 1. For the same prices, find the maximum profit possible with any number of buy/sell allowed (at each step/price, you can buy, sell or do nothing, no short sell allowed)2 Answers1) def roman_number(number): roman_char = {1000: 'M', 900: 'CM', 500: 'D', 400: 'CD', 100: 'C', 90: 'XC', 50: 'L', 40: 'XL', 10: 'X', 9: 'IX', 5: 'V', 4: 'IV', 1: 'I'} out = '' for val, c in roman_char.items(): if number < val: continue repeat, number = divmod(number, val) out += repeat * c return outC# static string IntToRoman(int i) { var bldr = new StringBuilder(7); var list = new List() { (1000, "M"), (900, "CM"), (500, "D"), (400, "CD"), (100, "C"), (90, "XC"), (50, "L"), (40, "XL"), (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I") }; foreach (var t in list) { int times = i / t.Item1; for (int q = 0; q < times; ++q) { bldr.Append(t.Item2); } i -= (times * t.Item1); if (i == 0) break; } return bldr.ToString(); }