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

201
Views
obtenga valor colocando otros 2 parámetros del mismo conjunto de la matriz json en fastAPI

Quiero obtener el valor de pred poniendo el valor de node1 y node2:

ESTA MI ARRAY DE DATOS

 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}, ]

ESTO LO HE PROBADO, soy nuevo en APIs

  1. esto me da todos los datos
 @app.get("/data/") async def get_all_predictions(skip: int = 0, limit: int = 10): return prediction_data[skip : skip + limit]
  1. esta es la función buscada pero por supuesto la incorrecta
 @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

por ejemplo, quiero escribir 0 y 1 y obtener como resultado pred = 0

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede filtrar una lista utilizando la función de filter integrada:

 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

Si es posible tener múltiples coincidencias, suelte el [0] y simplemente devuelva la lista completa en su lugar.

over 4 years ago · Santiago Trujillo Report
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!