Re: [Tutor] list comprehension with else

2015-01-19 Thread Sydney Shall
On 19/01/2015 00:55, Steven D'Aprano wrote: On Sun, Jan 18, 2015 at 02:20:55PM -0800, Danny Yoo wrote: Just to add, log(0) is mathematically undefined. https://en.m.wikipedia.org/wiki/Logarithm. For the record, IEEE-754 specifies that log(0.0) should return -INF. That's what Decimal does: py

Re: [Tutor] list comprehension with else

2015-01-18 Thread Steven D'Aprano
On Sun, Jan 18, 2015 at 02:20:55PM -0800, Danny Yoo wrote: Just to add, log(0) is mathematically undefined. https://en.m.wikipedia.org/wiki/Logarithm. For the record, IEEE-754 specifies that log(0.0) should return -INF. That's what Decimal does: py from decimal import Decimal py

Re: [Tutor] list comprehension with else

2015-01-18 Thread Alan Gauld
On 18/01/15 13:20, Sydney Shall wrote: I am a beginner and I have a question of syntax. Please don't hijack an existing thread. Simply changing the subject line is not enough. Always send a new mail to tutor@python.org to start a new discussion. Otherwise the new discussion gets interleaved

Re: [Tutor] list comprehension with else

2015-01-18 Thread Sydney Shall
On 18/01/2015 13:20, Sydney Shall wrote: I am a beginner and I have a question of syntax. I am just learning to use list comprehension, which oc course, I find very helpful indeed. However, I am stuck with a specific problem of how to incorporate an else in a list comp-rehension. I cannot do

Re: [Tutor] list comprehension with else

2015-01-18 Thread Asokan Pichai
On Sun, Jan 18, 2015 at 6:50 PM, Sydney Shall s.sh...@virginmedia.com wrote: I am a beginner and I have a question of syntax. Welcome! I am just learning to use list comprehension, which oc course, I find very helpful indeed. However, I am stuck with a specific problem of how to

Re: [Tutor] list comprehension with else

2015-01-18 Thread Alan Gauld
On 18/01/15 13:20, Sydney Shall wrote: The problem is I am occasionally getting exactly zeros when I need to obtain the logarithm of the number. for i in range(len(cap)): Its usually better to iterate over the collection rather than use indexing: for item in cap: if cap[i] ==

[Tutor] list comprehension with else

2015-01-18 Thread Sydney Shall
I am a beginner and I have a question of syntax. I am just learning to use list comprehension, which oc course, I find very helpful indeed. However, I am stuck with a specific problem of how to incorporate an else in a list comp-rehension. I cannot do it. The following snippet of code does

Re: [Tutor] list comprehension with else

2015-01-18 Thread Sydney Shall
On 18/01/2015 13:41, Asokan Pichai wrote: On Sun, Jan 18, 2015 at 6:50 PM, Sydney Shall s.sh...@virginmedia.com mailto:s.sh...@virginmedia.com wrote: I am a beginner and I have a question of syntax. Welcome! I am just learning to use list comprehension, which oc course, I find

Re: [Tutor] list comprehension with else

2015-01-18 Thread Danny Yoo
Just to add, log(0) is mathematically undefined. https://en.m.wikipedia.org/wiki/Logarithm. So depending on the problem's context, it might be worth asking why log is being applied on this input. Is such input expected? Make sure the code isn't trying to correct for input that shouldn't be