Code: Select all
#!/usr/bin/env python3
ipv4_list = ["192.168.1.2", "192.168.1.3", "192.168.1.4"]
ipv4_dic = {}
ipv4_len = len(ipv4_list)
i = 1
for val in range(len(ipv4_list)):
ipv4_dic[i] = ipv4_list[val]
i+=1
print(ipv4_dic)
Code: Select all
{1: '192.168.1.2', 2: '192.168.1.3', 3: '192.168.1.4'}
Wie mache ich das in der Zeile ipv4_dic = ipv4_list[key]
Ich habe so etwas wie ipv4_dic["IP"+i] versucht, aber es funktioniert nicht.
Code: Select all
ipv4_dic["IP"+i] = ipv4_list[val]
TypeError: can only concatenate str (not "int") to str
Code: Select all
{IP1: '192.168.1.2', IP2: '192.168.1.3', IP3: '192.168.1.4'}
Mobile version