'Printing Out Python Middle Values [closed]
How would you print out the middle values in a list, for example if a list is given [1, 2, 3, 4, 5], the values 2,3,4 would be printed out.
Solution 1:[1]
You can do this:
lst = [1, 2, 3, 4, 5]
print(lst[1:-1])
Solution 2:[2]
lst = list(range(1,6))
lst
Out[2]: [1, 2, 3, 4, 5]
lst[1:-1]
Out[3]: [2, 3, 4]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aly Mohamed |
| Solution 2 | The Photon |
