Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
Python Processing Multiple If Conditions Inside of a Return Statement

I am working on translating some code from JavaScript into Python.

In the Javascript I am seeing a lot of processing of multiple conditions inside of a return statement. Here's an example:

return '(' +
    Object.entries(query).map((kv) => {
    const key = getCols(kv[0], table)
    if (kv[0] === '$or') {
      return '(' + getQuery(kv[1], table).join(' OR ') + ')'
    } else if (kv[0] === '$null') {
      return format('%s IS NULL', kv[1])
    } else if (kv[0] === '$notnull') {
      return format('%s IS NOT NULL', kv[1])
    } else if (kv[0] === '$not') {
      return 'NOT (' + getQuery(kv[1], table) + ')'
    } else if (kv[0] === '$arrayany') {
      return Object.entries(kv[1])
        .map((x) => {
          return format('%s=ANY(%L)', getCols(x[0], table), value(x[1]))
        })
        .join(' AND ') +
        ')'

I haven't seen such complex return statements in Python and am not sure how to build an equivalent statement taking into account all the mappings and joins. What is a valid Pythonic way to have such deeply nested return statements?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!