Slice to Position in Python
To get a cut to any position, you need to specify only the ending index to the right of the colon. Let's output all the characters of the string up to the third index:
txt = 'abcde'
res = txt[:3]
print(res) # 'abc'
Given a string:
txt = '12345'
Get a slice of all its characters except the last one:
'1234'
Given a list:
lst = ['a', 'b', 'c', 'd', 'e']
Write the code to get the following slice:
['a', 'b']