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

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -