I have a list and want to join all except the last 2 entries i.e.
x = ["1", "2", "3", "4"]
print ', '.join(x[from 0 until -3])
Output would then be 1, 2
. How could I achieve this?
I have a list and want to join all except the last 2 entries i.e.
x = ["1", "2", "3", "4"]
print ', '.join(x[from 0 until -3])
Output would then be 1, 2
. How could I achieve this?
Use slicing
>>> x = ["1", "2", "3", "4"]
>>> print ', '.join(x[:-2])
1, 2