在python列表中,初始化时我不能在列表中存储31个以上的元素,我相信这可能是初始化期间允许的最大大小
例如(36个元素)
>>> valid_ip = [
... "192.0.0.100",
... "99.99.99.99",
... "0.99.99.99",
... "8.99.99.99",
... "85.99.99.99",
... "255.99.99.99",
... "55.255.255.0"
... "0.192.0.100",
... "99.99.99.99",
... "99.0.99.99",
... "99.8.99.99",
... "99.85.99.99",
... "99.255.99.99",
... "255.55.255.0"
... "100.0.192.192",
... "99.99.99.99",
... "99.99.0.0",
... "99.99.8.8",
... "99.99.85.85",
... "99.99.255.255",
... "255.55.0.255"
... "0.192.100.0",
... "99.99.99.99",
... "99.0.99.99",
... "99.8.99.99",
... "99.85.99.99",
... "99.255.99.99",
... "255.55.0.255"
... "0.255.255.55"
... "100.0.0.192",
... "99.99.99.99",
... "99.99.99.0",
... "99.99.99.8",
... "99.99.99.85",
... "99.99.99.255",
... "0.255.255.55"
... ]
>>>
>>> len(valid_ip)
31
我什至尝试通过拆分初始化来串联列表
valid_ip=[...]
valid_ip+=[...]
但长度仍然是31
或者,我可以存储在文件中并动态读取它,但是有什么方法可以增加文件大小?
答案 0 :(得分:5)
您缺少5个逗号,列出了31个元素而不是36个元素:
valid_ip = [
"192.0.0.100",
"99.99.99.99",
"0.99.99.99",
"8.99.99.99",
"85.99.99.99",
"255.99.99.99",
"55.255.255.0", # <<<
"0.192.0.100",
"99.99.99.99",
"99.0.99.99",
"99.8.99.99",
"99.85.99.99",
"99.255.99.99",
"255.55.255.0", # <<<
"100.0.192.192",
"99.99.99.99",
"99.99.0.0",
"99.99.8.8",
"99.99.85.85",
"99.99.255.255",
"255.55.0.255", # <<<
"0.192.100.0",
"99.99.99.99",
"99.0.99.99",
"99.8.99.99",
"99.85.99.99",
"99.255.99.99",
"255.55.0.255", # <<<
"0.255.255.55", # <<<
"100.0.0.192",
"99.99.99.99",
"99.99.99.0",
"99.99.99.8",
"99.99.99.85",
"99.99.99.255",
"0.255.255.55"
]
len(valid_ip)
# 36