0

List extraction

how do I only extract the number 4265 from this list. list = [None, None, None, None, None, None, '4265', None]

19th May 2017, 4:52 PM
buggythegret
buggythegret - avatar
4 ответов
+ 1
_list1 = [7163, True, "Potato", 7899, "UberPwnage9000"] x = _list1.index(7899) print(_list1[x])
19th May 2017, 4:57 PM
Sapphire
+ 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)
19th May 2017, 5:13 PM
Sapphire
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
19th May 2017, 5:06 PM
buggythegret
buggythegret - avatar
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.
19th May 2017, 7:51 PM
Igor B
Igor B - avatar