Python get first 2 elements of list

Python get first 2 elements of list
Luke Telford2,931 Points
Posted March 10, 2015 10:03am by Luke Telford
Luke Telford2,931 Points

How do i get the first 4 and last 4 items of a list?

So i have created a function and i need to get it to return the first and last 4 items of the list, how do i do this? i though returning [:4:-4] would work but it doesn't as this just returns 1

slices.py
def first_4(list): return list[:4] def odds(list): return list[1::2] def first_and_last_4(list): return list[:4:]