Change your code to 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 ls = sorted(ls) ls1 = sorted(ls1) ls.extend(ls1) return ls
regards, Sarma. On Fri, Apr 14, 2017 at 11:59 PM, shubham goyal <skgoyal...@gmail.com> wrote: > 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. > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor