Khalid Al-Ghamdi wrote:
Hi everyone!
I'm using python 3.1 and I want to to know why is it when I enter the
following in a dictionary comprehension:
>>> dc={y:x for y in list("khalid") for x in range(6)}
I get the following:
{'a': 5, 'd': 5, 'i': 5, 'h': 5, 'k': 5, 'l': 5}
instead of the exp
Hugo Arts dixit:
> bc = {y: x for x, y in enumerate("khalid")}
>
> Note that your output is like so:
> {'a': 2, 'd': 5, 'i': 4, 'h': 1, 'k': 0, 'l': 3}
>
> The first character in your original string gets a zero, the second a
> one, so on and so forth. I'm hoping that's what you meant. If you
>
Lie Ryan dixit:
> note that:
> >>> [(y, x) for y in list("khalid") for x in range(6)]
> [('k', 0), ('k', 1), ('k', 2), ('k', 3), ('k', 4), ('k', 5), ('h', 0),
> ('h', 1), ('h', 2), ('h', 3), ('h', 4), ('h', 5), ('a', 0), ('a', 1),
> ('a', 2), ('a', 3), ('a', 4), ('a', 5), ('l', 0), ('l', 1),
Khalid Al-Ghamdi wrote:
Hi everyone!
I'm using python 3.1 and I want to to know why is it when I enter the
following in a dictionary comprehension:
dc={y:x for y in list("khalid") for x in range(6)}
I get the following:
{'a': 5, 'd': 5, 'i': 5, 'h': 5, 'k': 5, 'l': 5}
instead of
On 12/4/2009 12:32 PM Khalid Al-Ghamdi said...
Hi everyone!
I'm using python 3.1 and I want to to know why is it when I enter the
following in a dictionary comprehension:
>>> dc={y:x for y in list("khalid") for x in range(6)}
Try breaking this into pieces...
First see what [(x,y) for y in
On Fri, Dec 4, 2009 at 9:32 PM, Khalid Al-Ghamdi wrote:
> Hi everyone!
> I'm using python 3.1 and I want to to know why is it when I enter the
> following in a dictionary comprehension:
dc={y:x for y in list("khalid") for x in range(6)}
> I get the following:
> {'a': 5, 'd': 5, 'i': 5, 'h': 5
On 12/5/2009 7:32 AM, Khalid Al-Ghamdi wrote:
Hi everyone!
I'm using python 3.1 and I want to to know why is it when I enter the
following in a dictionary comprehension:
>>> dc={y:x for y in list("khalid") for x in range(6)}
are you sure you want this?
{'a': 0, 'd': 1, 'i': 2, 'h': 3, 'k': 4
Hi everyone!
I'm using python 3.1 and I want to to know why is it when I enter the
following in a dictionary comprehension:
>>> dc={y:x for y in list("khalid") for x in range(6)}
I get the following:
{'a': 5, 'd': 5, 'i': 5, 'h': 5, 'k': 5, 'l': 5}
instead of the expected:
{'a': 0, 'd': 1, 'i':