What is the fastest and best way to get first value from list?
There are multiple techniques, but what is the best (memory and speed) and why?
Examples below. I would be grateful for other techniques as well:
listis = [1, 2, 3, 4]
### 1:
###----------
value = next(iter(listis))
print(value)
### 2:
###----------
value = listis[0]
print(value)
### 3:
###----------
value, *args = listis
print(value)
>Solution :
Calling the list element by its element number is always the fastest way. You aren’t doing any calculation nor using any functions to get to it.
print(listis[0])