复杂类型的python列表问题

时间:2015-09-18 09:37:04

标签: python list radix-tree capnproto

下面是Python中的代码片段,如果IP属于前缀,则将IP前缀存储在基数树中,然后将字典中的IP和ASN关联起来。

我想找出特定前缀的所有不同ASN。更多详情如下:

#rtree is a radix tree which has prefixes stored.
rtree = radix.Radix()    
with open(path-to-prefix-file,'r') as fp:
    for line in fp:
        rnode = rtree.add(line)  # Eg, Prefixes like "192.168.2.0/24"
        rnode.data["count"]= 0
...        
# The code has several lines here for processing a capnproto - skipping them.

rnode.data[IP]=asn_complete  # I read a Capnproto buffer and store IP and asn_complete

...

for rnode in rtree:
    seen_list = []  # defining a list to store different val, i.e.,asn_complete values
    if rnode.data["count"] > 1:
            """  Iterate through the rnode.data dictionary """
            for ip,val in rnode.data.iteritems():
                    if val not in seen_list:  # Condition is always satisfied!!
                            seen_list.append(val) 

例如:val在几次迭代中从protobuf中得到以下值:

[<capnp list reader [15169]>, <capnp list reader [1239]>, <capnp list reader [4837]>]

当我打印出seen_list

[[<capnp list reader [15169]>, <capnp list reader [1239]>, <capnp list reader [4837]>], [<capnp list reader [15169]>, <capnp list reader [1239]>, <capnp list reader [4837]>], [<capnp list reader [15169]>, <capnp list reader [1239]>, <capnp list reader [4837]>],....]

显然val位于seen_list;但是,if val not in seen_list:始终为真,并且val被多次附加到seen_list。我不明白为什么这种情况总是如此。是因为seen_list中存储的对象类型?

0 个答案:

没有答案