Python Interview Questions | Glassdoor

# Python Interview Questions

8

interview questions shared by candidates

## Python Interview Questions

Sort: RelevancePopular Date

May 26, 2013
 Write a function that takes in two sorted lists and outputs a sorted list that is their union.9 Answersf(a,b) { return sort(unique(a,b)) }def sortedUnion(list1,list2): list3 = [x for x in list1 if x in list2] return sorted(list(set(list3)))google merge sortShow More Responseswrite 2 helpers: 1) INSERT(A, b) = put element b within A in the sort order 2) DEL(A, a) = delete element a from A Then do this recursion: f(A,B) : if max(A) <= min(B) return [A B] else { B = INSERT(B, max(a)); A = DEL(A, max(a); f(A,B); } something like that. try coding and testing. I haven't.Oops, check/write a termination conditionOn Python, you could do: from sets import Set def merge_sort(a,b): return sorted( Set(a).union(Set(b)) )def sorted_union(list1, list2): union=set(list1).union(set(list2)) sorted_union=sorted(list(union)) return sorted_unionSecond part of merge sort. Don't answer with sort(a), etc. Anyone can do that... def merge(A, B): i=0 j=0 sorted_list = [] while i < len(A) and j < len(B): if A[i] <= B[j]: sorted_list.append(A[i]) i += 1 else: sorted_list.append(B[j]) j += 1 if i < len(A): sorted_list.extend(A[i:]) elif j < len(B): sorted_list.extend(B[j:]) return sorted_listI assumed that we can not use any "sort" function and we want it with linear time. so here it is: def my_sort(list_a, list_b): if len(list_a) ==0: return list_b elif len(list_b) ==0: return list_a else: if list_a[-1] > list_b[-1]: return( my_sort(list_a[0:-1], list_b) + [list_a.pop(-1)]) else: return(my_sort(list_a,list_b[:-1]) + [list_b.pop(-1)])

Feb 2, 2013
 Transform an integer to a string using only arithmetic operations. Known in C as 'itoa'.1 Answeryou can find the answer on google

### Signals Analyst at NSA was asked...

Dec 23, 2011
 Which programming language are you best skilled in? How do you feel about software engineering?1 AnswerThe favorite programming language should be Java, with Python being a close second. C++ is not important, but an additional knowledge of Matlab will help. Your interest shouldn't be limited to data analysis alone. Unless you are using simplified packages, you can't do good data analysis without a good knowledge of and interest in software engineering.

Oct 1, 2011
 Write a memory efficient string reverse function2 AnswersPython version def reverse( s ): l = len(s)-1 i = 0 while i <= l-i: t1 = s[i] t2 = s[l-i] s[l-i] = t1 s[i] = t2 i += 1 return ss = str[::-1]

### Senior Computational Linguist at Oracle was asked...

Jan 30, 2014
 Where are you from?1 AnswerI thought it was irrelevant

### Software Engineer In Test at Cloudera was asked...

Feb 10, 2017
 1. Detail working experience 2. Coding test for creating a BANK class with Python, including bank accounts, personal/bank money, deposit/withdraw methods ...Be the first to answer this question

### Senior Quality Assurance Engineer at Riverbed Technology was asked...

Feb 8, 2012
 Are strings mutable in python?1 Answer>>> a = 'str1' >>> a[3] = '2' Traceback (most recent call last): File "", line 1, in TypeError: 'str' object does not support item assignment >>> But let's take a look at example: >>> a = 'str1' >>> b = 'str2' >>> a = b >>> print a str2 >>> List is mutable: >>> a = ['s','t','r',1] >>> print a ['s', 't', 'r', 1] >>> a[3] = 2 >>> print a ['s', 't', 'r', 2] >>>

### MIS Co-Op at Siemens was asked...

Jul 4, 2011
 What is your favorite programming language? How do you use it?Be the first to answer this question
18 of 8 Interview Questions