Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- with open("C:\\Users\\Li\Downloads\\president MI.json", "r", encoding="utf8") as read_file:
- x = json.load(read_file)
- data = x["data"]["races"][0]["timeseries"]
- #print(data)
- last_votes = 0
- reduced_total = 0
- for i in data:
- if i['votes'] < last_votes:
- print(i['votes'] - last_votes)
- reduced_total = reduced_total + (i['votes'] - last_votes)
- last_votes = i['votes']
- print("total votes reduced: ", reduced_total)
- candidate = "trumpd"
- reduced_count = 0
- reduced_total = 0
- last_data = data[0]
- for i in data[1:]:
- votes = i['votes'] * i['vote_shares'][candidate]
- last_votes = last_data['votes'] * last_data['vote_shares'][candidate]
- if votes < last_votes:
- reduced_count = reduced_count + 1
- print(votes - last_votes)
- reduced_total += (votes - last_votes)
- last_data = i
- print(reduced_count)
- print("total votes taken from", candidate, ":", reduced_total)
- candidate = "bidenj"
- reduced_count = 0
- reduced_total = 0
- last_data = data[0]
- for i in data[1:]:
- votes = i['votes'] * i['vote_shares'][candidate]
- last_votes = last_data['votes'] * last_data['vote_shares'][candidate]
- if votes < last_votes:
- reduced_count = reduced_count + 1
- print(votes - last_votes)
- reduced_total += (votes - last_votes)
- last_data = i
- print(reduced_count)
- print("total votes taken from", candidate, ":", reduced_total)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement