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>
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 magnific
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 things
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 some
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
> ), sep='\n' )
>
>
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