Mar-11-2022, 09:26 AM
How can i seperate ip address and mac addresses??
['192.168.1.240,fe80::350e:d28d:14a5:5cbb']
How to seperate dict value?
|
Mar-11-2022, 09:26 AM
How can i seperate ip address and mac addresses??
['192.168.1.240,fe80::350e:d28d:14a5:5cbb']
Here is one way
for string in ['192.168.1.240,fe80::350e:d28d:14a5:5cbb']: new_string = string split_string = new_string.split(',') print(f'ip -> {split_string[0]}') print(f'mac -> {split_string[1]}') On a side note, this is a list. Not a dict.
I welcome all feedback.
The only dumb question, is one that doesn't get asked. My Github How to post code using bbtags Download my project scripts
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. |
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
Two separate dataframes, two seperate programs | stylingpat | 2 | 2,702 |
Apr-28-2021, 07:56 PM Last Post: stylingpat |
|
Seperate output buffer | matt_the_hall | 2 | 3,126 |
Mar-15-2021, 08:44 PM Last Post: matt_the_hall |
|
Sort a dict in dict | cherry_cherry | 4 | 104,337 |
Apr-08-2020, 12:25 PM Last Post: perfringo |
|
how to seperate words from string | zarize | 2 | 2,707 |
Aug-29-2019, 08:23 AM Last Post: zarize |
|
SQL connection in seperate file? | Tommy | 1 | 2,612 |
Jul-12-2019, 12:42 PM Last Post: ichabod801 |
|
Seperate entities in text file | bigdazza | 1 | 3,363 |
Jun-02-2018, 03:15 PM Last Post: snippsat |
|
how to start a seperate thread for every item in a list | lravikumarvsp | 1 | 3,462 |
May-31-2018, 08:07 AM Last Post: ThiefOfTime |