Mar-11-2022, 09:26 AM
Mar-11-2022, 10:36 AM
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]}')
Output:ip -> 192.168.1.240
mac -> fe80::350e:d28d:14a5:5cbb
On a side note, this is a list. Not a dict.Mar-11-2022, 10:48 AM
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'