#🔒 Need help with setting a condition

23 messages · Page 1 of 1 (latest)

grand shuttle
#

Is there a way to set a condition that checks for a 0 or less value in a dictionary? The value could be in any key and I need the check to apply to all keys

onyx pebbleBOT
#

@grand shuttle

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

chrome cave
#
list(filter(lambda x: x <= 0, {-1:"lala", 1: "baba"}))
[-1]
``` There it is. You can probably omit list, it's for nicer print
grand shuttle
#

Thanks

chrome cave
#

wait, that checks keys

#

use .values()

#

or dict comp if you want key-value pairs

grand shuttle
#

Nah only values thanks

chrome cave
#

that's key, though

#

was that what you wanted?

#

value is on rhs of :

grand shuttle
chrome cave
#

okkay

rustic aspen
#
any(v <= 0 for v in d.values())```
ocean atlas
ocean atlas
#

still funny to see

rustic aspen
#

Well, provided it's obvious what it is.

ocean atlas
#

I think it's one of those conventional one-letter variables

#

like you learn it by exposure

onyx pebbleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.