[exec cmd for cmd in cmds]

Scott David Daniels scott.daniels at acm.org
Wed Mar 8 16:21:45 CET 2006


Schüle Daniel wrote:
> you are right, I didn't think about dictionaries
>  >>> p = "complex(1-1e-%i, 1-1e-%i)"
>  >>> d={}
>  >>> [d.update({i:eval(p % (i,i))}) for i in range(20,30)]
> [None, None, None, None, None, None, None, None, None, None]
> 
> so now the work is complete :)
> 
> Regards
> 
Really, isn't this clearer?:

     d = {}
     for i in range(20, 30):
         v = 1. - 10. ** -i
         d[i] = complex(v, v)

If you must repair the mess above, try:

     p = "complex(1-1e-%i, 1-1e-%i)"
     d = dict([(i, eval(p % (i, i))) for i in range(20, 30)])

Strive to be clear first, terse second given the first is still
achieved.

--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list