"comprehend" into a single value
Andrew Z
formisc at gmail.com
Sun Oct 8 00:37:34 EDT 2017
Nathan, Bob - on the money. Thank you !
On Sat, Oct 7, 2017 at 11:30 PM, bob gailer <bgailer at gmail.com> wrote:
> On 10/7/2017 11:17 PM, Nathan Hilterbrand wrote:
>
>> dict= {10: ['a',1,'c'], 20: ['d',2,'f']}
>> p = sum([dict[i][1] for i in dict])
>>
>> Something like that?
>>
> Ah, but that's 2 lines.
>
> sum(val[1] for val in {10: ['a',1,'c'], 20: ['d',2,'f']}.values())
>
> On Sat, Oct 7, 2017 at 11:07 PM, Andrew Z <formisc at gmail.com> wrote:
>>
>> Hello,
>>> i wonder how can i accomplish the following as a one liner:
>>>
>>> dict= {10: ['a',1,'c'], 20: ['d',2,'f']}
>>> p = 0
>>> for i in dict:
>>> p += dict[i][1]
>>>
>>>
>>> Thank you
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>>>
>>>
> --
> Image and video hosting by TinyPic
>
More information about the Python-list
mailing list