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

205
Visualizações
get value by putting 2 other parameters of the same set from json array in fastAPI

I want to get the value of pred by putting node1 and node2 value:

THIS MY DATA ARRAY

prediction_data =[
  { "node1": 0, "node2": 1, "pred": 0},
  { "node1": 0, "node2": 476, "pred":0.352956 },
  { "node1": 0, "node2": 494, "pred":0.769988 },
  { "node1": 1, "node2": 505, "pred":0.463901 },
  { "node1": 9, "node2": 68 , "pred":1.238807},
    ]

THIS WHAT I HAVE TRIED, I'm new in APIs

  1. this gives me all data
@app.get("/data/")
async def get_all_predictions(skip: int = 0, limit: int = 10):
    return prediction_data[skip : skip + limit]
  1. this is the wanted function but of course the wrong one
@app.get("/data/{node1,node2}")
async def getPredOfN1andN2(node1,node2):
  if (node1 in prediction_data.node1) and (node2 in prediction_data.node2):
    result = prediction_data[pred]
  return result

for example, I want to write 0 and 1and get as result pred = 0

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can filter a list by using the built-in filter function:

async def getPredOfN1andN2(node1: int, node2: int):
    matching = list(filter(lambda x: x['node1'] == node1 and x['node2'] == node2, prediction_data))

    return matching[0]['pred'] if matching else None

If it's possible to have multiple matches, drop the [0] and just return the whole list instead.

over 4 years ago · Santiago Trujillo Relatório
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