Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
nested dictionary iteration
#1
Could anyone tell me how to iterate over a nested dictionary and replace the keys which have underscore and are in small letters ,to keys without underscore and camelcase.
Final dictionary should have keys without underscore and should be camelcase.
the logic i wrote is
d is the dictionary...
def printDict(d):
for oldkey, v in d.iteritems():
if type(v) is dict:
newkey=camel_case(old_key)
d[newkey]=d.pop[oldkey]
printDict(v)
else:
for oldkey, w in d.iteritems():
newkey=camel_case(old_key)
d[newkey]=d.pop[oldkey]

def camel_case(string)
title=string.title().replace("_","")
ca,el=title[0].lower+title[1:]
Reply


Messages In This Thread
nested dictionary iteration - by saisankalpj - Aug-31-2018, 02:02 PM
RE: nested dictionary iteration - by ichabod801 - Aug-31-2018, 02:26 PM
RE: nested dictionary iteration - by saisankalpj - Sep-01-2018, 04:20 AM
RE: nested dictionary iteration - by ichabod801 - Sep-01-2018, 12:00 PM
RE: nested dictionary iteration - by saisankalpj - Sep-02-2018, 04:10 PM
RE: nested dictionary iteration - by ichabod801 - Sep-02-2018, 05:00 PM
RE: nested dictionary iteration - by saisankalpj - Sep-02-2018, 05:54 PM
RE: nested dictionary iteration - by buran - Sep-02-2018, 07:16 PM
RE: nested dictionary iteration - by ichabod801 - Sep-02-2018, 07:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  need to compare 2 values in a nested dictionary jss 2 920 Nov-30-2023, 03:17 PM
Last Post: Pedroski55
  Nested dictionary acting strange Pedroski55 2 2,141 May-13-2021, 10:37 PM
Last Post: Pedroski55
  format the output from a nested dictionary. nostradamus64 9 4,673 May-03-2021, 04:45 PM
Last Post: nostradamus64
Lightbulb Python Nested Dictionary michaelserra 2 2,660 Apr-18-2021, 07:54 AM
Last Post: michaelserra
  new help with dictionary and dataframe iteration AlphFinan 0 1,553 Oct-13-2020, 11:04 PM
Last Post: AlphFinan
  nested dictionary rkpython 7 3,304 May-29-2020, 11:13 AM
Last Post: rkpython
  Nested Dictionary/List tonybrown3 5 3,212 May-08-2020, 01:27 AM
Last Post: tonybrown3
  Help: for loop with dictionary and nested lists mart79 1 1,896 Apr-12-2020, 02:52 PM
Last Post: TomToad
  Transforming nested key-tuples into their dictionary values ClassicalSoul 4 2,715 Apr-11-2020, 04:36 PM
Last Post: bowlofred
  Dictionary iteration and creation a new dictionary from duplicates xrsxlnx 2 2,180 Mar-30-2020, 10:43 AM
Last Post: xrsxlnx

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020