I have some data I have zipped together using itertools.zip_longest
import itertools
names = 'Tim Bob Julian Carmen Sofia Mike Kim Andre'.split()
locations = 'DE ES AUS NL BR US'.split()
confirmed = [False, True, True, False, True]
zipped_up = list(itertools.zip_longest(names, locations, confirmed))
if I print zipped_up the way it is now I get the following:
[('Tim', 'DE', False), ('Bob', 'ES', True),
('Julian','AUS', True), ('Carmen', 'NL', False),
('Sofia', 'BR',True), ('Mike', 'US', None),
('Kim',None, None),('Andre', None, None)]
This is fine, the missing values are given "None" as a default. Now I want to change the "None" values to '-'.
It seems like I should be able to do so in the following nested loops. If I include a print statement in the code below, it appears everything works the way I wanted:
for items in zipped_up:
for thing in items:
if thing == None:
thing = '-'
print(thing)
But if I print zipped_up again (outside the loops), the 'None' values have not changed. Why Not? Is it something to do with the data type of the list items, which are tuples?
I have referenced some other stackoverflow threads including this one but have been unable to use it: finding and replacing elements in a list (python)