Python list comprehension Remove duplicates

后端 未结 2 1602
孤街浪徒
孤街浪徒 2021-01-27 07:32

I want unique elements in hubcode_list. I can do it by

hubcode_alarm_obj = HubAlarm.objects.all()
for obj in hubcode_alarm_obj:
    hubcode = obj.h         


        
2条回答
  •  一个人的身影
    2021-01-27 08:23

    Since you are using django, let the database do the filtering for you. It will be (by far) the fastest option:

    objects = HubAlarm.objects.exclude(hubcode__in=hubcode_list)
    

    See the documentation for more.

提交回复
热议问题