fork download
  1. #Python 3, but should be fine in python 2 except prints.
  2.  
  3. def main():
  4. a = [int(num) for num in input("Enter list one: ").split(' ')]
  5. b = [int(num) for num in input("Enter list two: ").split(' ')]
  6. newlist1 = intersection(a,b)
  7. print(newlist1)
  8.  
  9. def intersection(a,b):
  10. newlist = []
  11.  
  12. for num in a:
  13. if num in b:
  14. newlist.append(num)
  15.  
  16. return newlist
  17.  
  18. if __name__ == "__main__":
  19. main()
Success #stdin #stdout 0.1s 10104KB
stdin
1 2 3 4 5
45 5 7 8 9
stdout
Enter list one: Enter list two: [5]