Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to seperate dict value?
#3
You have list with one string item in it. Obvious way would be splitting this item at comma and unpack:

>>> line = ['192.168.1.240,fe80::350e:d28d:14a5:5cbb']
>>> ip_addr, mac_addr = line[0].split(',')
>>> ip_addr
'192.168.1.240'
>>> mac_addr
'fe80::350e:d28d:14a5:5cbb'
If the result should be dictionary then one could do this:

>>> data = dict(zip(('ip_addr', 'mac_addr'), line[0].split(',')))
>>> data
{'ip_addr': '192.168.1.240', 'mac_addr': 'fe80::350e:d28d:14a5:5cbb'}
>>> data['ip_addr']
'192.168.1.240'
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
How to seperate dict value? - by ilknurg - Mar-11-2022, 09:26 AM
RE: How to seperate dict value? - by menator01 - Mar-11-2022, 10:36 AM
RE: How to seperate dict value? - by perfringo - Mar-11-2022, 10:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Two separate dataframes, two seperate programs stylingpat 2 2,063 Apr-28-2021, 07:56 PM
Last Post: stylingpat
  Seperate output buffer matt_the_hall 2 2,441 Mar-15-2021, 08:44 PM
Last Post: matt_the_hall
  Sort a dict in dict cherry_cherry 4 91,352 Apr-08-2020, 12:25 PM
Last Post: perfringo
  how to seperate words from string zarize 2 2,128 Aug-29-2019, 08:23 AM
Last Post: zarize
  SQL connection in seperate file? Tommy 1 2,126 Jul-12-2019, 12:42 PM
Last Post: ichabod801
  Seperate entities in text file bigdazza 1 2,882 Jun-02-2018, 03:15 PM
Last Post: snippsat
  how to start a seperate thread for every item in a list lravikumarvsp 1 2,979 May-31-2018, 08:07 AM
Last Post: ThiefOfTime

Forum Jump:

User Panel Messages

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