Yes, there is. You can use the following list-comprehention.
newArray = [x[:6] for x in y]
Slicing has the following syntax: list[start:end:step]
Arguments:
start - starting integer where the slicing of the object starts
stop - integer until which the slicing takes place. The slicing stops at index stop - 1.
step - integer value which determines the increment between each index for slicing
Examples:
list[start:end] # get items from start to end-1
list[start:] # get items from start to the rest of the list
list[:end] # get items from the beginning to the end-1 ( WHAT YOU WANT )
list[:] # get a copy of the original list
if the start or end is -negative, it will count from the end
list[-1] # last item
list[-2:] # last two items
list[:-2] # everything except the last two items
list[::-1] # REVERSE the list
Demo:
let's say I have an array = ["doctorWho","Daleks","Cyborgs","Tardis","SonicSqrewDriver"]
and I want to get the first 3 items.
>>> array[:3] # 0, 1, 2 (.. then it stops)
['doctorWho', 'Daleks', 'Cyborgs']
(or I decided to reverse it):
>>> array[::-1]
['SonicSqrewDriver', 'Tardis', 'Cyborgs', 'Daleks', 'doctorWho']
(now i'd like to get the last item)
>>> array[-1]
'SonicSqrewDriver'
(or last 3 items)
>>> array[-3:]
['Cyborgs', 'Tardis', 'SonicSqrewDriver']