-3
import json


def read_json(filename):

    dt = {}

    fh = open(filename, "r")
    dt = json.load(fh)

    return dt


def print_values_order_by_keys(dt):

    sorted_keys = sorted(dt)
    print sorted_keys


filename = raw_input("Enter the JSON file: ")


r = read_json(filename)

print_values_order_by_keys(r)

I am trying to print the objects in the alphabetic order of the keys. I was able to sort the keys in alphabetic order, but when I print them it gives me the keys and not the objects contained in them. Any advice?

enter image description here

  • I'm not trying to remove the u of unicode, just trying to print the objects instead of the keys on separate lines. My bad, I forgot to change the title of my previous question – helpmeplease Feb 22 '17 at 14:11

1 Answers1

0

You need to print the strings separately; you are just printing a string representation of the list that contains the strings.

def print_values_order_by_keys(dt):
    print "[%s]" % (', '.join(sorted(dt)),)
chepner
  • 497,756
  • 71
  • 530
  • 681