How to write python list inclusions to remove duplication

Asked 2 years ago, Updated 2 years ago, 20 views

Get a query_set and
Due to duplicate values in hoge column,
I would like to eliminate duplicates.
I'd like to write this in a list format. How should I write it?

want_list=[]
pass_hoge_list = [ ]
for i in list(query_set):
  if not i.get(hoge) in pass_hoge_list:
    pass_hoge_list.append(i.get('hoge')))
    want_list.append(i)

python

2022-09-30 14:09

1 Answers

 {i.get("hoge"):i for i in query_set}.values()

Is it like this?


2022-09-30 14:09

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.