I'm having a bit of an issue with a while/if statement.
I have a list of values, normally these values will be strings, but sometimes it can return None. Here are two of my attempts:
x = ['One','Two','Three',None,None]
New = []
count=0
for y in x:
while isinstance(y,str):
New.append(y)
count+=1
break
else:
count+=1
New.append('New - '+str(count))
print New,count
>>> The list repeats several times
New = []
for y in x:
count=0
if y is not None:
New.append(y)
count+=1
else:
count+=1
New.append('New - '+str(count))
>>>['One','Two','Three','New - 1','New - 1']
I would like the output to be: ['One','Two','Three', 'New - 4', 'New - 5'], and to keep the ordering of the list if the None value was somewhere in the middle.
I'm not sure where I'm going wrong, neither of them are far off. Sorry if this is quite simple i'm still learning. I've looked around this forum for a similar query, some have helped but i still can;t figure it out.
Nonewith a string'New - {number}'where{number}is the position of the item, 1-indexed?