Converting tuple of lists of variable length into dictionary
Beppe
giuseppecostanzi at gmail.com
Sun Oct 18 08:44:07 EDT 2015
Il giorno domenica 18 ottobre 2015 14:35:53 UTC+2, Chris Angelico ha scritto:
> On Sun, Oct 18, 2015 at 11:23 PM, Beppe <giuseppecostanzi at gmail.com> wrote:
> > hi Peter, you are right, no duplicates are admitted between lists,
> > anyway your solution,works on python 3 but not on 2.
> > however beautiful list comprehension solution.
> > I will try to suit it for the python version i need
>
> Should work fine on 2.7. What Py2 version are you running?
>
> ChrisA
Python2.6
Python 2.6.6 (r266:84292, Aug 12 2014, 07:57:07)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> lists = (['a', 'b', 'c', 'd', 'e', 'f'], ['g', 'h', 'i'], ['l', 'm','n', 'o'])
>>>
... d = {c: items[:i] + items[i+1:] for items in lists for i, c in enumerate(items)}
File "<stdin>", line 2
d = {c: items[:i] + items[i+1:] for items in lists for i, c in enumerate(items)}
^
SyntaxError: invalid syntax
More information about the Python-list
mailing list