Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda