Python interview questions in programming— part2
This is part2 of programming questions in python. You can refer Part1 for more interview questions. You can find all these source coed in the GitHub.
- Given two list, first is numerators and second list is denominators. Sort both list in such a way that fraction of numerator/denominator value should be sorted order.( Asked in Altimetrik interview)
Input: numes = [1, 3, 4, 5, 6] denoms = [1, 2, 3, 4, 6]
Output: [1, 6, 5, 4, 3], [1, 6, 4, 3, 2]
2. Implement simple decorator(Foraysoft)
- This is very common and popular question you will get in python interviews.
- I faced this question in almost all interviews I attended.
3. Find list of sequence of lists from the given list of integers, return empty if no sequence numbers in the given list
Input: [1, 2, 3, 6, 8, 9, 5, 6]
Output: [[1, 2, 3], [8, 9], [5, 6]]
4. Print all the keys from a given complex dictionary, use recursive approach(TrackMind)
Input: a = {1: {2: {3: “hi”}, 4: {5: “Hello”}}}
Output: [1,2,3,4,5]
5. Given a dictionary contains list as values, sort dictionary with nth element from list time of the value in the dictionary.(TrackMind)
Input: {“a”: [1, 10, 3], “b”: [5, 0, 7], “c”: [7, 1, 9]}
Output: {‘b’: [5, 0, 7], ‘c’: [7, 1, 9], ‘a’: [1, 10, 3]}
6. Print infinite sequence
- Printing infinite sequence is one of the best examples of using yield keyword
- Infinite sequence method is a generator as we are using yield in the function
7. Given three list, print items in position-wise as list, assume length of all lists are equal(TrackMind)
Input: a = [1, 2, 3], b = [4, 5, 6], c = [7, 8, 9]
Output: [[1,4,7] [2,5,8] [3,6,9]]
- This can be done by using zip() function