0
List extraction
how do I only extract the number 4265 from this list. list = [None, None, None, None, None, None, '4265', None]
4 Réponses
+ 1
_list1 = [7163, True, "Potato", 7899, "UberPwnage9000"]
x = _list1.index(7899)
print(_list1[x])
+ 1
You weren't specific about that detail in your original post...
Regardless:
_list1 = [None, None, None, 6, None]
for value in _list1:
if value != None:
print (value)
0
This might work if I already have the value I am extracting. I will be getting the value for the first time and the position of the value is also not fixed. The other items in the list other than the value will be a None type
0
If you know for sure that there is at least 1 non-None value in the list then:
filter(None, mylistt)[0]
P.S. Don't use "list" for naming your variables since that hides the built-in type.