Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
2 Antworten
4403 Ansichten

I have a list which collect data, and at one point it returns None and i need to replace this None with a 0. How can i get this done in openerp 7

Avatar
Verwerfen
Beste Antwort

You can iterate the list and check the condition. If you get None value it will insert 0 in new list.

>>> a = [1,2,3,'c',None]

>>> b = []

>>> for x in a:

... if x is None:

... b.append(0)

... else:

... b.append(x)

...

>>> b

[1, 2, 3, 'c', 0]

Avatar
Verwerfen
Autor

Thank You @Krutarath,

Already i have done that this way,

late_duration = [['a', 1], ['b', 4], ['c', None]]

late_duration_val_list = [[None if isinstance(b, int) else 0 if b == None else b for b in i] for i in late_duration]

late_duration.append(late_duration_val_list)

print (late_duration_val_list)

Output is,

[['a', None], ['b', None], ['c', 0]]

Verknüpfte Beiträge Antworten Ansichten Aktivität
3
Aug. 15
22866
1
März 15
6479
0
Feb. 16
3078
2
Aug. 15
6792
1
Aug. 15
4793