Q:

How can i generate a dictionary from a list and remove all whitespaces

I have the following list of 'arp -a' command output which is continuous as long as devices in the network are detected.
['XX.1.60.XX                ether   XX:16:35:b2:c9:XX   C                     wlan0', 'XXX.168.42.XXX           ether   XX:35:cd:e8:a5:XX   C                     usb0', 'XX.1.62.XXX              ether   XX:9f:db:72:61:XX   C                     wlan0', '']

I wish to generate a dictionary with the ip address as the key and hardware address as the value ie:
{ 'XX.1.60.XX': XX:16:35:b2:c9:XX, 'XXX.168.42.XXX': 'XX:35:cd:e8:a5:XX'}

A:

Use split() to cut your line into words
data = ['XX.1.60.XX                ether   XX:16:35:b2:c9:XX   C                     wlan0', 'XXX.168.42.XXX           ether   XX:35:cd:e8:a5:XX   C                     usb0', 'XX.1.62.XXX              ether   XX:9f:db:72:61:XX   C                     wlan0', '']

result = {}
for line in data:
    try:
        ip, _, hardware, _, _ = line.split()
        result[ip] = hardware
    except ValueError:
        # bad line format
        pass

print(result)
# {'XX.1.60.XX': 'XX:16:35:b2:c9:XX', 'XXX.168.42.XXX': 'XX:35:cd:e8:a5:XX', 'XX.1.62.XXX': 'XX:9f:db:72:61:XX'}

