[英]How to add properties to a list of dicts via a list comprehension in python3?
[英]How to add mac into list in python3?
我指的是我从此表单复制的代码,但我希望将Mac添加/添加到列表中。
mac = '00:00:00:'
for number in range(16**6):
hex_num = hex(number)[2:].zfill(6)
print("{}{}{}:{}{}:{}{}".format(mac,*hex_num))
您可以使用列表理解来构造这样的列表:
mac = '00:00:00:'
the_list = ["{}{}{}:{}{}:{}{}".format(mac,*hex(number)[2:].zfill(6))
for number in range(16**6)]
请注意,由于16 6 = 16 777 216,将花费一些时间来生成列表,此外,它将消耗大量的内存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.