0

Hope you guys help me to Get same object in multi Querysets in Python. I use Django Framework

I assumed that I have 2 Queryset:

qrs1 = [1, 2, 3, 5, 9]

and

qrs2 = [1, 4, 2, 5]

I want to print result with this queryset:

[1, 2, 5]
KitKit
  • 6,971
  • 11
  • 44
  • 74

2 Answers2

1

You can cast your first queryset to set and call intersection method of this set.

set(qrs1).intersection(qrs2)
Dima Kudosh
  • 6,456
  • 4
  • 34
  • 46
1
 qrs1 = [1, 2, 3, 5, 9]
 qrs2 = [1, 4, 2, 5]
 list(set(qrs1).intersection(qrs2))

you just need an intersection of the querysets

Exprator
  • 25,406
  • 6
  • 40
  • 52