Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
looping through lists
#2
& is bitwise and
it is not quite the same as boolean and

>>> [(x,y,z) for x in [1, 2, 3] for y in [1, 2, 3] for z in [1, 2, 3] if x != y & x != z & y != z]
[(1, 2, 3), (2, 1, 3), (3, 1, 2), (3, 2, 1)]
>>> [(x,y,z) for x in [1, 2, 3] for y in [1, 2, 3] for z in [1, 2, 3] if x != y and x != z and y != z]
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
Reply


Messages In This Thread
looping through lists - by brianl - Jan-10-2018, 05:52 PM
RE: looping through lists - by buran - Jan-10-2018, 06:58 PM
RE: looping through lists - by brianl - Jan-10-2018, 07:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Populate the new lists by looping over the original lists drunkenphd 1 1,540 Oct-10-2020, 02:54 AM
Last Post: Skaperen
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,449 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  How to concatenate files while looping through lists? python_newbie09 3 2,924 Mar-24-2019, 03:11 PM
Last Post: python_newbie09
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,321 Mar-20-2019, 08:01 PM
Last Post: stillsen

Forum Jump:

User Panel Messages

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