Chrome Extension

[Python] Using comprehension expression to convert list of dictionaries to nested dictionary

# yaml file used for account 
- sitename: testcomp
  email: test@outlook.com
  pass: 111
  role: admin
  name: admin
- sitename: testcomp
  email: mvsubmit@gmail.com
  pass: 111
  role: edit
  name: user1
- sitename: testcomp
  email: test2@outlook.com
  pass: 11
  role: edit
  name: user2

# convert.py
    # read yaml file into faccounts
    faccounts = yaml.load(file, Loader=yaml.FullLoader)
    # Convert list of dictionaries to nested dictionary so that we can select any value by user name and key nam
    account = {account['name']: account for account in faccounts}
    return account
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool
Was this helpful?
0 Comments
Join Devsheet Ask a Question