[Tutor] sorted function
shubham goyal
skgoyal721 at gmail.com
Fri Apr 14 14:29:25 EDT 2017
Dear mentors,
sorted function is not working when i am trying to sort the list of strings
but list.sort() is working. can you please help me understand.In this
question i was trying to sort the list but first sorting the letter
starting from x and taking them first.
def front_x(words):
# +++your code here+++
ls=[]
ls1=[]
for str in words:
if str[0]=='x':
ls.append(str)
else:
ls1.append(str);
print ls
print ls1
sorted(ls)
sorted(ls1)
ls.extend(ls1)
return ls
front_x(['bbb', 'ccc', 'axx', 'xzz', 'xaa'])
Output:['xzz', 'xaa', 'bbb', 'ccc', 'axx']
Output should be: ['xaa', 'xzz', 'axx', 'bbb', 'ccc']
Thankyou. Sorry for bad writing skills.
More information about the Tutor
mailing list