PYTHON   19

intersect py

Guest on 5th August 2022 02:58:47 PM

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. def intersect(list_a, list_b):
  5.     res = []
  6.     for el in list_a:
  7.         if el in list_b:
  8.             res.append(el)
  9.     return res
  10.  
  11. in_both = intersect([1,2,3,4],[0,2,4,6])
  12. print in_both
  13.  
  14. in_both = intersect([1,2,3,4],(0,2,4,6))
  15. print in_both
  16.  
  17. in_both = intersect(['a','b','c','d'],'Acdfgh')
  18. print in_both
  19.  
  20. in_both = intersect('abcd','Acdfgh')
  21. print in_both

Raw Paste


Login or Register to edit or fork this paste. It's free.