Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding Variable
#5
(Feb-18-2019, 08:16 AM)Lonewolf Wrote: if the lists have the same lenght you could use something like that:
[Vals1[i]+Vals2[i] for i in range(len(Vals1))]

As ichabod801 already mentioned this is not Pythonic way i.e. needlessly complex and verbose. Just:

[sum(pair) for pair in zip(vals1, vals2)]
However, this is not recursive solution what OP needs.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Adding Variable - by kevinwoo00 - Feb-18-2019, 03:51 AM
RE: Adding Variable - by Lonewolf - Feb-18-2019, 08:16 AM
RE: Adding Variable - by perfringo - Feb-18-2019, 04:51 PM
RE: Adding Variable - by ichabod801 - Feb-18-2019, 04:17 PM
RE: Adding Variable - by ichabod801 - Feb-18-2019, 04:18 PM

Forum Jump:

User Panel Messages

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