Python Forum
Best form of iterating over a lsit of lists
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best form of iterating over a lsit of lists
#10
Thanks for answering but I think you've misunderstood my question. I'm trying to understand the difference in these:

for name, species, weight in pets:
     print(name, species, weight)
 
for [name, species, weight] in pets:
     print(name, species, weight)
 
for (name, species, weight) in pets:
     print(name, species, weight)
Especially the last two. I know what they do, but is there a difference? Asked another way, does it make a difference if you use () or [] on the left hand side of an assignment? If not in my case, does it ever make a difference if there is a tuple (or other iterable) on the right hand side?
Reply


Messages In This Thread
RE: Best form of iterating over a lsit of lists - by tonymcgregor - Oct-15-2017, 09:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,539 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  Iterating through lists with different letter cases fatherted99 2 1,949 Jun-07-2020, 01:22 PM
Last Post: deanhystad
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,416 Mar-20-2019, 08:01 PM
Last Post: stillsen
  Iterating over two lists in python dgm 2 3,068 Jul-24-2018, 08:31 PM
Last Post: dgm
  iterating over N lists in parallel Skaperen 6 5,282 Mar-24-2017, 06:51 AM
Last Post: buran

Forum Jump:

User Panel Messages

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