Dict lookup shortcut?

M. Clift noone at here.com
Tue Oct 12 13:39:23 CEST 2004


Hi All,

Can someone tell me is there a shorthand version to do this?

l1 = ['n1', 'n3', 'n1'...'n23'...etc...]

Names = {'n1':'Cuthbert','n2' :'Grub','n3' :'Dibble' etc...}

for name in l1:
    print Names[name],

Rather than listing all the name+numbers keys in the dictionary can these
keys be shortened somehow into one key and a range?

Thanks,

M





More information about the Python-list mailing list