Python Forum
Thread Rating:
  • 3 Vote(s) - 3.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
matching question
#4
Using list comprehensions or sets are common ways to solve this.
>>> participants = ('bob','bill','casey')
>>> paid = ('bob', 'bill')
>>> [x for x in participants if x in paid]
['bob', 'bill']
>>> len([x for x in participants if x in paid])
2

>>> list(set(participants).intersection(set(paid)))
['bob', 'bill']
>>> set(participants) & set(paid)
{'bob', 'bill'}
>>> 
Reply


Messages In This Thread
matching question - by takaa - Nov-21-2017, 10:14 AM
RE: matching question - by heiner55 - Nov-21-2017, 11:11 AM
RE: matching question - by takaa - Nov-21-2017, 11:35 AM
RE: matching question - by snippsat - Nov-21-2017, 01:55 PM
RE: matching question - by heiner55 - Nov-21-2017, 02:29 PM
RE: matching question - by takaa - Nov-21-2017, 03:10 PM
RE: matching question - by heiner55 - Nov-21-2017, 03:19 PM
RE: matching question - by takaa - Nov-21-2017, 04:11 PM
RE: matching question - by iFunKtion - Nov-21-2017, 07:01 PM
RE: matching question - by takaa - Nov-23-2017, 10:14 AM
RE: matching question - by heiner55 - Nov-23-2017, 08:33 AM
RE: matching question - by heiner55 - Nov-23-2017, 11:34 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020