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

204
Views
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 answers
Answer question

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 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!