Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding two lists
#6
Why use indexing at all - when you have zip?
[val2 if val1 == 'null' else val1 for val1, val2 in zip(list1, list2)]

PS Recommended form to check type - isinstance

if isinstance(value, int):
.....
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Messages In This Thread
Adding two lists - by KaleBosRatjes - Jun-04-2018, 07:15 PM
RE: Adding two lists - by j.crater - Jun-04-2018, 08:00 PM
RE: Adding two lists - by KaleBosRatjes - Jun-04-2018, 08:13 PM
RE: Adding two lists - by j.crater - Jun-04-2018, 08:26 PM
RE: Adding two lists - by KaleBosRatjes - Jun-04-2018, 08:26 PM
RE: Adding two lists - by volcano63 - Jun-04-2018, 08:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,430 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  Adding markers to Folium map only adding last element. tantony 0 2,152 Oct-16-2019, 03:28 PM
Last Post: tantony
  adding lists to lists? ivinjjunior 5 3,095 Apr-15-2019, 07:41 PM
Last Post: ivinjjunior
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,318 Mar-20-2019, 08:01 PM
Last Post: stillsen
  Help on adding two lists recursively Metalman488 3 4,203 Sep-16-2018, 08:10 PM
Last Post: Metalman488

Forum Jump:

User Panel Messages

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