list comprehension question

Mike C. Fletcher mcfletch at rogers.com
Sun Aug 11 16:10:58 EDT 2002


x is a list of range(2,12) for the 1 element in list.  Lists don't have 
a ** (number) operator defined.

try "print list" to see what's going on.
 >>> list = [range(2, 12)]
 >>> print list
[[2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]
 >>>

BTW, it's good practice not to name variables after the builtin 
functions/types (such as list).

HTH,
Mike

brobbins333 at shaw.ca wrote:
> Why doesn't this work?
> 
> list = [range(2, 12)]
> [(x ** 2) + x + 2 for x in list]
> 
> error: unsupported operand type for **


-- 
_______________________________________
   Mike C. Fletcher
   Designer, VR Plumber, Coder
   http://members.rogers.com/mcfletch/






More information about the Python-list mailing list