How to write python list inclusions to remove duplication

Asked 5 months ago, Updated 5 months ago, 11 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


© 2023 OneMinuteCode. All rights reserved.