Hlelp clean up clumpsy code

It's me itsme at yahoo.com
Tue Jan 4 01:38:23 EST 2005


Another newbie question.

There must be a cleaner way to do this in Python:

#### section of C looking Python code ####
a = [[1,5,2], 8, 4]
a_list = {}
i = 0
for x in a:
    if isinstance(x, (int, long)):
        x = [x,]
    for w in [y for y in x]:
        i = i + 1
        a_list[w] = i
print a_list
#####

The code prints what I want but it looks so "C-like".  How can I make it
more Python like?

Thanks,






More information about the Python-list mailing list