⊗pyPmSlRS 84 of 208 menu

Reversing a Sequence in Python

To reverse all elements of a sequence, specify a step with a negative value:

txt = '123456789' res = txt[::-1] print(res) # '987654321'

Given a string:

txt = '12345'

Turn it over:

'54321'

Given a list:

lst = ['c', 'b', 'a']

Turn it over:

['a', 'b', 'c']

Given a string:

txt = '123456789'

Get a slice of all its symbols at even positions in reverse order:

'8642'
byenru