I thought you guys would suggest something like this

def parseOffsets(str):
    seq = str.split()
    dict = {}
    while seq != []:
        name, x, y = seq[:3]
        dict[name] = (int(x),int(y))
        del seq[:3]
    return dict

which seems to me as something in more of python-spirit? :D

well, anyways, thanks - now i know i dont have to bend backwards with restricting myself from using simple old paradigms (like for loop) in my python code (:

Cheers!

On 08/09/2010 17:13, Vernon Cole wrote:
If you bring up Python in interactive mode, and type "import this", some sage advice will appear:
v v v v v
C:\Users\vernon>ipy
C:\Users\vernon>"c:\program files\IronPython 2.7\ipy.exe"
IronPython 2.7 Alpha 1 (2.7.0.1) on .NET 4.0.30319.1
>>> import this

Explicit is better than implicit.
Simple is better than complex.
Readability counts.
^ ^ ^ ^

In that spirit, may I suggest the following simple, readable code?
<code>
ml = ['name1','x1','y1','name2','x2','y2']
i = 0
d = {}
while True:
    try:
        d[ml[i]] = (ml[i+1],ml[i+2])
    except IndexError:
        break
    i += 3
print repr(d)
</code>

On Wed, Sep 8, 2010 at 5:29 AM, Iivari Mokelainen <iiv...@mokelainen.com <mailto:iiv...@mokelainen.com>> wrote:

     I need to unpack a list of
       [name, x, y, name, x, y]
    to a dictionary
       {name : (x,y), name:(x,y)}
    how would one do that?

    Also, is it ok to ask such newbie questions here, or is there a
    better place for that?

    _______________________________________________
    Users mailing list
    Users@lists.ironpython.com <mailto:Users@lists.ironpython.com>
    http://lists.ironpython.com/listinfo.cgi/users-ironpython.com




_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to