for/ if against dict - one liner

Thomas Jollans tjol at tjol.eu
Tue Nov 14 04:54:29 EST 2017


On 2017-11-14 06:44, Andrew Z wrote:
> Hello,
>  i wonder how do i get the "for" and "if" to work against a dictionary in
> one line?
> 
> basically i want to "squeeze":
>  dct= [ 1 : "one", 2:"two", 3:"three"]
>  for k, val in dct:

Don't you mean dct.items()

>    if k >= 2:
>       # do magnificent things
> 
> Thank you
> AZ
> 


-- 
Thomas Jollans



More information about the Python-list mailing list