Is there a nicer way to do this?
Victor B. Gonzalez
python.comp.lang.id982 at vbgunz.com
Thu Oct 4 18:17:52 EDT 2007
On Thursday 04 October 2007 5:07:51 pm Stefan Arentz wrote:
> Is there a better way to do the following?
>
> attributes = ['foo', 'bar']
>
> attributeNames = {}
> n = 1
> for attribute in attributes:
> attributeNames["AttributeName.%d" % n] = attribute
> n = n + 1
>
> It works, but I am wondering if there is a more pythonic way to
> do this.
>
> S.
just curious. why are you bothering in creating a dictionary? why not just
iterate over attributes? why duplicate it and make it bigger? I personally
think the dictionary is unnecessary but I may be wrong.
anyhow, I keep getting "SyntaxError: Non-ASCII character '\xc2'..." on line 5.
anyone know what this is? I couldn't run the script but from looking at it,
it appears you're making some pointless keys when indexes may be better.
--
Best Regards
Victor B. Gonzalez
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20071004/22208046/attachment.sig>
More information about the Python-list
mailing list