Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. “””
  2. List of possible questions for python coding interview.
  3. Meant to be flexible so pick and choose from the outline as we please.
  4. I created more questions than someone could probably answer in the
  5. allotted time anyway so we can choose a subset.
  6. “””
  7.  
  8. # Print the keys from the given dictionary person
  9. person = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
  10.  
  11. # Write a simple unit test for your method
  12.  
  13. # ----------------------------------------------------------
  14. # Return a single list of unique names given two seperate lists of names
  15. names1 = ['Olivia', 'Amy', 'Emily', 'Jack', 'Charlie', 'Bill', 'Ray', 'Mia']
  16. names2 = ['John', 'Steven', 'Amy', 'Ray', 'Jason', 'Mia', 'Emilio']
  17.  
  18. # ----------------------------------------------------------
  19. # Create two lists. One with all even and another with all odd numbers from the given list below.
  20. nums = [3, 1, 10, 4, 8, 11, 2, 6, 9, 0, 5, 7]
  21.  
  22. # ----------------------------------------------------------
  23. Tell me about generators.
  24. Possible questions
  25.     What is an iterable.
  26.     What two methods do iterable objects implement
  27.     What is the difference between a generator and a list
  28.     What is lazy evaluation
  29.  
  30. # Write a generator method that prints from 0 to n given n
  31.  
  32. # Given the simple generator function, what will be printed to the console?
  33. def my_gen():
  34.     n = 1
  35.     print('This is printed first')
  36.     yield n
  37.  
  38.     n += 1
  39.     print('This is printed second')
  40.     yield n
  41.  
  42.     n += 1
  43.     print('This is printed at last')
  44.     yield n
  45.    
  46.  
  47. next(my_gen())
  48. next(my_gen())
  49. next(my_gen())
  50. next(my_gen())
  51.  
  52. # What about
  53. g = my_gen()
  54. next(g)
  55. next(g)
  56. next(g)
  57. next(g)
  58.  
  59. # Or
  60. print(next(g))
  61. print(next(g))
  62. print(next(g))
  63. print(next(g))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement