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 what I need. But, perhaps I am solving this math error problem incorrectly. 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)):
        if cap[i] == 0.0:
            tmp = math.log(1.0)
            lncap.append(tmp)
        else:
            lncap.append(math.log(cap[i]))

I have set mu options to plain text.
--
Sydney
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to