python function slowing down for no apparent reason

后端 未结 6 1021
小鲜肉
小鲜肉 2021-01-22 16:56

I have a python function defined as follows which i use to delete from list1 the items which are already in list2. I am using python 2.6.2 on windows XP

def comp         


        
6条回答
  •  执念已碎
    2021-01-22 17:50

    The often suggested set wont work here, because the two lists contain lists, which are unhashable. You need to change your data structure first.

    You can

    • convert the sublists into tuples or class instances to make them hashable, then use sets.
    • Keep both lists sorted, then you just have to compare the lists' heads.

提交回复
热议问题