Reversing a list in python 3 -
using python 3, need reverse elements in lists given number (yet determined). example:
list1 = edud - become dude list2 = mobbed - become bombed list3 = edud - remains same
can use range , append functions, reverse function not used , needs in python loops. suggestions??
so far have this, it's wrong:
def reverse(list, number): in range (0,length(my_list)-1): num in number: if num == number: new_list.append(my_list[i-num]) return new_list
well, question little confusing me. "reverse" read list ending beginning. said, reversed version of mobbed
should debbom
. nevertheless, easiest way accomplish in python using slices.
the basics:
a = 'mother' a[::-1] = 'rehtom' a[2:4] = 'th' a[2:5] = 'the'
any sort of transformation you're trying do, can done slicing , joining pieces again
Comments
Post a Comment