1

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

Omar
  • 27
  • 6

1 Answers1

0

you can use one dict to reference another one

for k, v in initial,items():
    from_other_dict = current.get(k,'')
    print(k, v, ','.join(from_other_dict), sep=",")
galaxyan
  • 5,944
  • 2
  • 19
  • 43
  • This seems to work But any idea how can I get rid of the unicode format output? Example output: 146783,bodewig,[u'damjan', u'damjan'] is there a way to display without the u' ' ? Thanks again – Omar Oct 13 '17 at 17:22
  • @Omar try it now – galaxyan Oct 13 '17 at 17:57