I am new to Python so I don't have much experience, sorry if this is a stupid question.
I am reading a bunch of Json files and storing some values into 2 separate dictionaries. I am trying to output the results as the following: ID, Current name, Initial name But I'm not sure how to go through both dictionaries in a single for loop. What I have so far is the following:
for dev, dev2 in zip(current.items(), initial.items()):
print(dev, dev2, sep=",")
The names of the dictionaries are current and initial . The output for this however is repeating the ID, so I have: (ID, [current]) , (ID, [initial]) and the formatting has some random unicode characters, so I'm not sure how to go around this
Any help would be appreciated!
This is the full code: (I have Python 2.7.10 btw)
from __future__ import print_function
import json
import os
import io
import shutil
current = {}
initial = {}
for file in os.listdir('.'):
if not ".json" in file:
continue
data = io.open(file, 'r', encoding="utf8")
commit = json.load(data)
for branch in commit["branches"]:
for change in branch["methodChanges"]:
method_name = change["methodProperties"]["name"]
change_type = change["methodChangeProperties"]["changeOperation"]
if method_name in current:
current[method_name].append(commit["committer"])
else:
current[method_name] = [commit["committer"]]
if change_type == "ADDED":
initial[method_name] = commit["committer"]
print("Method","Current Developer","Initial Developer", sep=",")
#for dev in current:
#print(dev, current[dev], sep=",")
#for dev2 in initial:
#print(dev2, initial[dev2], sep=",")
for dev, dev2 in zip(current.items(), initial.items()):
print(dev, dev2, sep=",")
Each of the print functions in the commented for loops in the end do work separately, I'm trying to combine both the outputs in one table by matching the first field though. The output I'm trying to get is a table with the ID (called name), Current, Initial