Re: [Tutor] sorted function

2017-04-15 Thread shubham goyal
Thankyou. got it. On Sat, Apr 15, 2017 at 5:44 AM, Steven D'Aprano wrote: > On Fri, Apr 14, 2017 at 11:59:25PM +0530, shubham goyal wrote: > > > sorted(ls) > > sorted(ls1) > > Here you sort ls and throw the result away, then you do the same to ls1. > > sorted() makes a copy of the list and s

Re: [Tutor] sorted function

2017-04-14 Thread Steven D'Aprano
On Fri, Apr 14, 2017 at 11:59:25PM +0530, shubham goyal wrote: > sorted(ls) > sorted(ls1) Here you sort ls and throw the result away, then you do the same to ls1. sorted() makes a copy of the list and sorts it. You need to write: ls = sorted(ls) ls1 = sorted(ls1) but even better would be t

Re: [Tutor] sorted function

2017-04-14 Thread D . V . N . Sarma డి . వి . ఎన్ . శర్మ
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. O

Re: [Tutor] sorted function

2017-04-14 Thread Alan Gauld via Tutor
On 14/04/17 19:29, shubham goyal wrote: > 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. sort() sorts the list "in place". That is it sorts itself. sorted() returns a sorted copy of the list. It does not

[Tutor] sorted function

2017-04-14 Thread shubham goyal
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