Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
issue in using dictionary
#3
(Nov-23-2018, 02:22 PM)ODIS Wrote: Hello amar,

you can do it like this:

lines = [
    {'name':'ename','data':'str','len':'2','add':'bgl','out':'y','zip':'3567','add/blr':'Y'},
    {'name':'another_name','data':'str','len':'2','add':'bgl','out':'y','zip':'3567','add/blr':'Y'}
]

result = {}

for line in lines:
    # extract the name from the line
    name = line["name"]
    # delete the name from the line
    del (line["name"])
    # make the record in result
    result[name] = line

print(result)

Hi,

DO i need to convert dict to list again like below, coz there are many rows .. coz im reading csv to df and doing json.loads to get dict

lines = [
{'name':'ename','data':'str','len':'2','add':'bgl','out':'y','zip':'3567','add/blr':'Y'},
{'name':'another_name','data':'str','len':'2','add':'bgl','out':'y','zip':'3567','add/blr':'Y'}
]
Reply


Messages In This Thread
issue in using dictionary - by amar - Nov-23-2018, 12:59 PM
RE: issue in using dictionary - by ODIS - Nov-23-2018, 02:22 PM
RE: issue in using dictionary - by amar - Nov-24-2018, 01:18 PM
RE: issue in using dictionary - by ichabod801 - Nov-24-2018, 04:35 PM
RE: issue in using dictionary - by amar - Nov-26-2018, 04:18 AM
RE: issue in using dictionary - by ODIS - Nov-26-2018, 10:45 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Issue accessing data from Dictionary/List in the right format LuisSatch 2 2,297 Jul-25-2020, 06:12 AM
Last Post: LuisSatch
  Nested dictionary issue Will86 3 3,011 Apr-16-2019, 11:58 PM
Last Post: Will86

Forum Jump:

User Panel Messages

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