Reversing list with strings in python -
i have list,
last_names = [ 'hag ', 'hag ', 'basmestad ', 'grimlavaag ', 'kleivesund ', 'fintenes ', 'svalesand ', 'molteby ', 'hegesen ']
and want print reversed, 'hegesen' comes first, ' molteby' , @ end 'hag'.
i have tried last_names.reverse()
, returnes none..
any help?
.reverse
returns none
because reverses in-place:
>>> last_names = [ ... 'hag ', 'hag ', 'basmestad ', 'grimlavaag ', 'kleivesund ', ... 'fintenes ', 'svalesand ', 'molteby ', 'hegesen '] >>> last_names.reverse() >>> last_names ['hegesen ', 'molteby ', 'svalesand ', 'fintenes ', 'kleivesund ', 'grimlavaag ', 'basmestad ', 'hag ', 'hag ']
to in expression, last_names[::-1]
.
Comments
Post a Comment