Change None to Float in List of Strings (Python)

Viewed 5879

I have a long list of strings in the following format:

    [...
    (0.5, 'house', 'flower'),
    (0.213, 'garden', 'flowerpot'),
    (None, 'mulch', 'hunting'),
    (0.9, 'flower', 'tulip'),
    (0.34, 'party', 'music'),
    (None, 'piano', 'trowel'),
    (0.138, 'fertilizer', 'cow')
    ...]

And before I can sort the list based on the first element, I have to convert the None types to floats. How do I change all the Nones in the list to float 0?

I am trying:

mylist = map(lambda x: 0 if x[0] == None, else x, mylist)

But somewhere I am going wrong with the syntax - anyone have advice for a Pythonic replace all on Nones in the first element of each string for the whole list?

2 Answers
Related