I,m recently started learning python, so I'm sure that are many things that I don't know that may be quite simple to solve. However, searching through a lot of questions I couldn't find an answer to this one.
Is it possible to iterate an variable in a dictionary comprehension statement?
While searching for an answer I've found this:
{ _key : _value(_key) for _key in _container }
Wich, I'm now aware, is a way of looping inside the comprehension, but for this to work for me, I need to be able to iterate the value for each '_key' in the '_container'.
For a very basic example:
alphabet = 'abcdefghijklmnopqrstuvwxyz'
x = 1
alpha_numbers = {char : x for char in alphabet}
I would like 'x' to be 'x += 1' for each 'char' in the 'alphabet' container. But every way I try to iterate it, inside the dictionary comprehension, returns a 'Invalid Syntax' error.
So, is it possible to do it? Or there is a better way to make it?
Thanks in advance.