data = ['cat', 'dog', 'None', 'Turtle', 'None']
new_data = []
for item in data:
if item == 'None':
new_data.append(data.index(item))
print new_data
>> [2,2]
How do I go about getting to this store new data as [2,4]? This is what I want. Thank you!
Use enumerate() while looping. This will track both, the current item and its index:
[index for index, x in enumerate(data) if x == "None"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With