Re: for/ if against dict - one liner

2017-11-18 Thread Andrew Z
Gentlemen, thank you very much for the replies and help. Vincent's solution worked perfectly for me. Alister - you are correct and for me, i was looking to achieve that - readability and slightly less keystrokes. On Tue, Nov 14, 2017 at 4:59 AM, alister via Python-list < python-list@python.org>

Re: for/ if against dict - one liner

2017-11-14 Thread Thomas Jollans
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

Re: for/ if against dict - one liner

2017-11-14 Thread alister via Python-list
On Tue, 14 Nov 2017 00:44:18 -0500, 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: >if k >= 2: > # do magnificent

Re: for/ if against dict - one liner

2017-11-14 Thread Vincent Vande Vyvre
Le 14/11/17 à 06:44, Andrew Z a écrit : 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: if k >= 2: # do magnificent things Thank you AZ Maybe

Re: for/ if against dict - one liner

2017-11-14 Thread Thomas Jollans
On 2017-11-14 07:29, Stefan Ram wrote: > Andrew Z writes: >> i wonder how do i get the "for" and "if" to work against a dictionary in >> one line? > > dict ={ 1 : "one", 2 : "two", 3 : "three" } > print( *( ( str( key )+ ' ' + str( dict[ key ])) for key in dict if key >= 2 >

for/ if against dict - one liner

2017-11-13 Thread Andrew Z
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: if k >= 2: # do magnificent things Thank you AZ -- https://mail.python.org/mailman/listinfo/python-list