Why does this list swap fail?

2016-11-14 Thread 380162267qq
L=[2,1] L[0],L[L[0]-1]=L[L[0]-1],L[0] The L doesn't change. Can someone provide me the detail procedure of this expression? -- https://mail.python.org/mailman/listinfo/python-list

How make the judge with for loop?

2016-10-15 Thread 380162267qq
c="abcdefghijk" len=len(c) n is a int sb=[[] for i in range(n)] while (i < len) { for (int j = 0; j < n && i < len; j++) sb[j].append(c[i++]); for (int j = n-2; j >= 1 && i < len; j--) // sb[j].append(c[i++]); } How to translate to python? I tried

Re: How to sort this without 'cmp=' in python 3?

2016-10-15 Thread 380162267qq
在 2016年10月14日星期五 UTC-4下午7:35:08,38016...@gmail.com写道: > nums=['3','30','34','32','9','5'] > I need to sort the list in order to get the largest number string: '953433230' > > nums.sort(cmp=lambda a,b: cmp(a+b, b+a), reverse=True) > > But how to do this in python 3? > > Thank you !I learn mo

How to sort this without 'cmp=' in python 3?

2016-10-14 Thread 380162267qq
nums=['3','30','34','32','9','5'] I need to sort the list in order to get the largest number string: '953433230' nums.sort(cmp=lambda a,b: cmp(a+b, b+a), reverse=True) But how to do this in python 3? Thank you -- https://mail.python.org/mailman/listinfo/python-list

I am comfused about the name behavior of Python in recursion

2016-10-05 Thread 380162267qq
Google told me Python name is a label attaching to the object. But in this recursive function,the name 'a' will point to different number object. def rec(a): a+=1 if a<10: rec(a) print(a) rec(0) gives me 101 normally.Why it works? Because of the stack

Re: Need help for the print() function with a better order

2016-10-02 Thread 380162267qq
在 2016年10月2日星期日 UTC-4下午1:05:58,Peter Pearson写道: > On Sat, 1 Oct 2016 18:12:29 -0700 (PDT), 38016226...@gmail.com wrote: > > I am trying to print a simple decision tree for my homework. > > The answer must keep in this format: > > > > Top 7,4,0.95 > > career gain = 100 > > 1.Management 2, 3, 0.9

Need help for the print() function with a better order

2016-10-01 Thread 380162267qq
I am trying to print a simple decision tree for my homework. The answer must keep in this format: Top 7,4,0.95 career gain = 100 1.Management 2, 3, 0.9709505944546686 2.Service 5, 1, 0.6500224216483541 location gain = 100 1.Oregon 4, 1, 0.7219280948873623 2.Californ

Is 'learning python 5th edition' a good book to beginner?

2016-09-25 Thread 380162267qq
I want to find a python book like C++ primer which provides me details to understand the language. -- https://mail.python.org/mailman/listinfo/python-list

Why does the insert after list function fail?

2016-09-22 Thread 380162267qq
A=["1","2","3"] print(list(map(float,A)).insert(0,1)) I want to insert 1 at the head of the list but this gives me a surprise -- https://mail.python.org/mailman/listinfo/python-list

Re: I am newbie who can explain this code to me?

2016-09-22 Thread 380162267qq
在 2016年9月20日星期二 UTC-4下午3:11:27,Terry Reedy写道: > On 9/20/2016 9:12 AM, Peter Otten wrote: > > >> 在 2016年9月20日星期二 UTC-4上午8:17:13,BartC写道: > >>> On 20/09/2016 13:12, 38016226...@gmail.com wrote: > >>> d = {} > >>> keys = range(256) > >>> vals = map(chr, keys) > >>> map(operator.setite

Re: What does this zip() code mean?

2016-09-20 Thread 380162267qq
在 2016年9月20日星期二 UTC-4上午9:35:50,Random832写道: > On Tue, Sep 20, 2016, at 09:19, 38016226...@gmail.com wrote: > > >>> x = [1, 2, 3] > > >>> y = [4, 5, 6] > > >>> zipped = zip(x, y) > > >>> list(zipped) > > [(1, 4), (2, 5), (3, 6)] > > >>> x2, y2 = zip(*zip(x, y)) > > >>> x == list(x2) and y == list(y2

Re: I am newbie who can explain this code to me?

2016-09-20 Thread 380162267qq
在 2016年9月20日星期二 UTC-4上午9:13:35,Peter Otten写道: > 38016226...@gmail.com wrote: > > > 在 2016年9月20日星期二 UTC-4上午8:17:13,BartC写道: > >> On 20/09/2016 13:12, 38016226...@gmail.com wrote: > >> d = {} > >> keys = range(256) > >> vals = map(chr, keys) > >> map(operator.setitem, [d]*len(key

What does this zip() code mean?

2016-09-20 Thread 380162267qq
>>> x = [1, 2, 3] >>> y = [4, 5, 6] >>> zipped = zip(x, y) >>> list(zipped) [(1, 4), (2, 5), (3, 6)] >>> x2, y2 = zip(*zip(x, y)) >>> x == list(x2) and y == list(y2) True My problem is >>> x2, y2 = zip(*zip(x, y)). zip return an iterator but x2 and y2 are different? I really need detail explanatio

Re: I am newbie who can explain this code to me?

2016-09-20 Thread 380162267qq
在 2016年9月20日星期二 UTC-4上午8:17:13,BartC写道: > On 20/09/2016 13:12, 38016226...@gmail.com wrote: > d = {} > keys = range(256) > vals = map(chr, keys) > map(operator.setitem, [d]*len(keys), keys, vals) > > > > It is from python library. What does [d]*len(keys) mean? > > d is the name

I am newbie who can explain this code to me?

2016-09-20 Thread 380162267qq
>>> d = {} >>> keys = range(256) >>> vals = map(chr, keys) >>> map(operator.setitem, [d]*len(keys), keys, vals) It is from python library. What does [d]*len(keys) mean? d is the name of dict but put d in [] really confused me. -- https://mail.python.org/mailman/listinfo/python-list