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
  • 8,549
  • 12
  • 56
  • 82

2 Answers2

1

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

set(qrs1).intersection(qrs2)
Dima Kudosh
  • 7,126
  • 4
  • 36
  • 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
  • 26,992
  • 6
  • 47
  • 59