Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
enumeration code help
#3
Sure can! So we have a base of understanding, here's your current code:
>>> tmp = [
... [1, 2, 3, 4],
... [5, 6, 7, 8],
... [9, 10, 11, 12]
... ]
>>> newList = []
>>> for rec in tmp:
...   newList.append([rec[0]*2, rec[1]*2, rec[3]*2])
...
>>> newList
[[2, 4, 8], [10, 12, 16], [18, 20, 24]]
Here's a list comprehension that does the same:
>>> [[a*2, b*2, d*2] for a,b,c,d in tmp]
[[2, 4, 8], [10, 12, 16], [18, 20, 24]]
Reply


Messages In This Thread
enumeration code help - by sar - Jan-22-2019, 04:56 PM
RE: enumeration code help - by ichabod801 - Jan-22-2019, 05:14 PM
RE: enumeration code help - by nilamo - Jan-22-2019, 05:14 PM
RE: enumeration code help - by perfringo - Jan-22-2019, 05:15 PM
RE: enumeration code help - by sar - Jan-22-2019, 05:50 PM
RE: enumeration code help - by DeaD_EyE - Jan-22-2019, 06:30 PM

Forum Jump:

User Panel Messages

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