Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda