Re: Append to python List
Chris Angelico writes: On Thu, May 9, 2013 at 9:30 PM, Jussi Piitulainen wrote: 8 Dihedral writes: This is just the handy style for a non-critical loop. In a critical loop, the number of the total operation counts does matter in the execution speed. Do you use speed often? Dihedral is a bot. Quite a good one, but a bot. Yes, I understood why people say so when it followed up to something I wrote myself, and what it wrote made no sense in the context. My response was also generated by a bot: M-x doctor in Emacs, meant to be funny. Don't worry, I'm not going to engage it further. -- http://mail.python.org/mailman/listinfo/python-list
Re: Append to python List
On Thu, May 9, 2013 at 9:30 PM, Jussi Piitulainen jpiit...@ling.helsinki.fi wrote: 8 Dihedral writes: This is just the handy style for a non-critical loop. In a critical loop, the number of the total operation counts does matter in the execution speed. Do you use speed often? Dihedral is a bot. Quite a good one, but a bot. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Append to python List
Chris Angelico ros...@gmail.com writes: On Thu, May 9, 2013 at 9:30 PM, Jussi Piitulainen jpiit...@ling.helsinki.fi wrote: 8 Dihedral writes: This is just the handy style for a non-critical loop. In a critical loop, the number of the total operation counts does matter in the execution speed. Do you use speed often? Dihedral is a bot. Quite a good one, but a bot. That's been said often enough. Is the source available and is it in Python? -- http://mail.python.org/mailman/listinfo/python-list
Re: Append to python List
On Sun, May 12, 2013 at 1:47 AM, Anssi Saari a...@sci.fi wrote: Chris Angelico ros...@gmail.com writes: On Thu, May 9, 2013 at 9:30 PM, Jussi Piitulainen jpiit...@ling.helsinki.fi wrote: 8 Dihedral writes: This is just the handy style for a non-critical loop. In a critical loop, the number of the total operation counts does matter in the execution speed. Do you use speed often? Dihedral is a bot. Quite a good one, but a bot. That's been said often enough. Is the source available and is it in Python? Not to my knowledge. Technically Dihedral is merely _rumoured_ to be a bot, as we have no actual proof; but we've been conducting a variety of Turing tests via this list and have yet to see any strong argument for his being deemed human. Most humans would get defensive, or at least protest, if treated as bots; Dihedral never has, despite being referred to in this way a number of times. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Append to python List
Chris Angelico於 2013年5月12日星期日UTC+8上午12時00分44秒寫道: On Sun, May 12, 2013 at 1:47 AM, Anssi Saari a...@sci.fi wrote: Chris Angelico ros...@gmail.com writes: On Thu, May 9, 2013 at 9:30 PM, Jussi Piitulainen jpiit...@ling.helsinki.fi wrote: 8 Dihedral writes: This is just the handy style for a non-critical loop. In a critical loop, the number of the total operation counts does matter in the execution speed. Do you use speed often? Dihedral is a bot. Quite a good one, but a bot. That's been said often enough. Is the source available and is it in Python? Not to my knowledge. Technically Dihedral is merely _rumoured_ to be a bot, as we have no actual proof; but we've been conducting a variety of Turing tests via this list and have yet to see any strong argument for his being deemed human. Most humans would get defensive, or at least protest, if treated as bots; Dihedral never has, despite being referred to in this way a number of times. ChrisA Don't you get the practices of POSIX ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Append to python List
On Sun, May 12, 2013 at 12:29 PM, 8 Dihedral dihedral88...@googlemail.com wrote: Chris Angelico於 2013年5月12日星期日UTC+8上午12時00分44秒寫道: Most humans would get defensive, or at least protest, if treated as bots; Dihedral never has, despite being referred to in this way a number of times. ChrisA Don't you get the practices of POSIX ? I rest my case, m'lud. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Append to python List
Jussi Piitulainen於 2013年5月9日星期四UTC+8下午7時30分05秒寫道: 8 Dihedral writes: This is just the handy style for a non-critical loop. In a critical loop, the number of the total operation counts does matter in the execution speed. Do you use speed often? There is another concern about the list construction part in programming. Although a typical PC is installed with gaga bytes of DRAM now, anything that will use more memory from the heap dynamically could fail in the run time. It is the programmer's job to identify this kind of sources in minds. -- http://mail.python.org/mailman/listinfo/python-list
Append to python List
Checkout the following code: sample2 = [x+y for x in range(1,10) for y in range(1,10) if x!=y] output=[] output=[x for x in sample2 if x not in output] the output I get is 3 4 5 6 7 8 9 10 3 5 6 7 8 9 10 11 4 5 7 8 9 10 11 12 5 6 7 9 10 11 12 13 6 7 8 9 11 12 13 14 7 8 9 10 11 13 14 15 8 9 10 11 12 13 15 16 9 10 11 12 13 14 15 17 10 11 12 13 14 15 16 17 which contains duplicate values. But if I do like this: sample2 = [x+y for x in range(1,10) for y in range(1,10) if x!=y] output=[] for x in sample2: if x not in output: output.append(x) the value of 'output' I get like this: 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 I know that both the programs have the same functionality, but why do I have different outputs? Please help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Append to python List
RAHUL RAJ writes: Checkout the following code: sample2 = [x+y for x in range(1,10) for y in range(1,10) if x!=y] output=[] output=[x for x in sample2 if x not in output] the output I get is 3 4 5 6 7 8 9 10 3 5 6 7 8 9 10 11 4 5 7 8 9 10 11 12 5 6 7 9 10 11 12 13 6 7 8 9 11 12 13 14 7 8 9 10 11 13 14 15 8 9 10 11 12 13 15 16 9 10 11 12 13 14 15 17 10 11 12 13 14 15 16 17 which contains duplicate values. The second comprehension, [x for x in sample2 if x not in output], in the context, is equivalent to [x for x in sample2 if x not in []]. It does not refer to an incomplete version of the list that gets assigned to the variable after it's done. -- http://mail.python.org/mailman/listinfo/python-list
Re: Append to python List
On 05/08/2013 11:36 PM, RAHUL RAJ wrote: Checkout the following code: sample2 = [x+y for x in range(1,10) for y in range(1,10) if x!=y] output=[] output=[x for x in sample2 if x not in output] This statement is not doing what you expect. It is not building a list in the variable named output, it is building a list (anonymously) then binding it to the variable output once it's built. Therefore output is [] for the whole list building operation. The later operation works, because your *are* building the list in place as you go. the output I get is 3 4 5 6 7 8 9 10 3 5 6 7 8 9 10 11 4 5 7 8 9 10 11 12 5 6 7 9 10 11 12 13 6 7 8 9 11 12 13 14 7 8 9 10 11 13 14 15 8 9 10 11 12 13 15 16 9 10 11 12 13 14 15 17 10 11 12 13 14 15 16 17 which contains duplicate values. But if I do like this: sample2 = [x+y for x in range(1,10) for y in range(1,10) if x!=y] output=[] for x in sample2: if x not in output: output.append(x) the value of 'output' I get like this: 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 I know that both the programs have the same functionality, but why do I have different outputs? Please help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Append to python List
On Thu, May 9, 2013 at 4:36 PM, RAHUL RAJ omrahulraj...@gmail.com wrote: output=[x for x in sample2 if x not in output] output=[] for x in sample2: if x not in output: output.append(x) The first one constructs a list, then points the name 'output' at it. The second one builds up a list, with 'output' pointing at it all the way. Your first one is more like: sample2 = [x+y for x in range(1,10) for y in range(1,10) if x!=y] output=[] _temp=[] for x in sample2: if x not in output: _temp.append(x) output=_temp You may want to consider using a set, instead. {x+y for x in range(1,10) for y in range(1,10) if x!=y} {3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17} ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Append to python List
Then what about this code part? [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y] and the following code part: for x in [1,2,3]: for y in [3,1,4]: if x != y: combs.append((x, y)) On Thursday, May 9, 2013 12:24:24 PM UTC+5:30, Gary Herron wrote: On 05/08/2013 11:36 PM, RAHUL RAJ wrote: Checkout the following code: sample2 = [x+y for x in range(1,10) for y in range(1,10) if x!=y] output=[] output=[x for x in sample2 if x not in output] This statement is not doing what you expect. It is not building a list in the variable named output, it is building a list (anonymously) then binding it to the variable output once it's built. Therefore output is [] for the whole list building operation. The later operation works, because your *are* building the list in place as you go. the output I get is 3 4 5 6 7 8 9 10 3 5 6 7 8 9 10 11 4 5 7 8 9 10 11 12 5 6 7 9 10 11 12 13 6 7 8 9 11 12 13 14 7 8 9 10 11 13 14 15 8 9 10 11 12 13 15 16 9 10 11 12 13 14 15 17 10 11 12 13 14 15 16 17 which contains duplicate values. But if I do like this: sample2 = [x+y for x in range(1,10) for y in range(1,10) if x!=y] output=[] for x in sample2: if x not in output: output.append(x) the value of 'output' I get like this: 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 I know that both the programs have the same functionality, but why do I have different outputs? Please help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Append to python List
I'm getting same output for both code parts, why not for th code parts in question? On Thursday, May 9, 2013 1:48:51 PM UTC+5:30, RAHUL RAJ wrote: Then what about this code part? [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y] and the following code part: for x in [1,2,3]: for y in [3,1,4]: if x != y: combs.append((x, y)) On Thursday, May 9, 2013 12:24:24 PM UTC+5:30, Gary Herron wrote: On 05/08/2013 11:36 PM, RAHUL RAJ wrote: Checkout the following code: sample2 = [x+y for x in range(1,10) for y in range(1,10) if x!=y] output=[] output=[x for x in sample2 if x not in output] This statement is not doing what you expect. It is not building a list in the variable named output, it is building a list (anonymously) then binding it to the variable output once it's built. Therefore output is [] for the whole list building operation. The later operation works, because your *are* building the list in place as you go. the output I get is 3 4 5 6 7 8 9 10 3 5 6 7 8 9 10 11 4 5 7 8 9 10 11 12 5 6 7 9 10 11 12 13 6 7 8 9 11 12 13 14 7 8 9 10 11 13 14 15 8 9 10 11 12 13 15 16 9 10 11 12 13 14 15 17 10 11 12 13 14 15 16 17 which contains duplicate values. But if I do like this: sample2 = [x+y for x in range(1,10) for y in range(1,10) if x!=y] output=[] for x in sample2: if x not in output: output.append(x) the value of 'output' I get like this: 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 I know that both the programs have the same functionality, but why do I have different outputs? Please help! -- http://mail.python.org/mailman/listinfo/python-list
Re: Append to python List
On Thu, 09 May 2013 01:18:51 -0700, RAHUL RAJ wrote: Then what about this code part? What about it? [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y] and the following code part: for x in [1,2,3]: for y in [3,1,4]: if x != y: combs.append((x, y)) Apart from not defined combs, those two pieces of code are equivalent. So what is your question? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Append to python List
Jussi Piitulainen於 2013年5月9日星期四UTC+8下午2時55分20秒寫道: RAHUL RAJ writes: Checkout the following code: sample2 = [x+y for x in range(1,10) for y in range(1,10) if x!=y] output=[] output=[x for x in sample2 if x not in output] the output I get is 3 4 5 6 7 8 9 10 3 5 6 7 8 9 10 11 4 5 7 8 9 10 11 12 5 6 7 9 10 11 12 13 6 7 8 9 11 12 13 14 7 8 9 10 11 13 14 15 8 9 10 11 12 13 15 16 9 10 11 12 13 14 15 17 10 11 12 13 14 15 16 17 which contains duplicate values. The second comprehension, [x for x in sample2 if x not in output], in the context, is equivalent to [x for x in sample2 if x not in []]. It does not refer to an incomplete version of the list that gets assigned to the variable after it's done. This is just the handy style for a non-critical loop. In a critical loop, the number of the total operation counts does matter in the execution speed. -- http://mail.python.org/mailman/listinfo/python-list
Re: Append to python List
8 Dihedral writes: This is just the handy style for a non-critical loop. In a critical loop, the number of the total operation counts does matter in the execution speed. Do you use speed often? -- http://mail.python.org/mailman/listinfo/python-list