Reputation: 809
i need to find out the common first_name ( not case sensitive ) of the mail [email protected]
i'm using MongoDb and MongoEngine
. how the query should be in normal ORM
User list:
first_name = 'Anish Menon'
email = '[email protected]'
first_name = 'Hari Dev'
email = '[email protected]'
first_name = 'anish MenoN'
email = '[email protected]'
Initial:
Users = User.objects.filter(email='[email protected]')
for user in Users:
--------------
Upvotes: 0
Views: 94
Reputation: 1122
What about:
import operator
Then in your loop, get a list of the first_name in lowercase:
list = []
list.append(user.first_name.lower()) # to have lowercase strings
then, count the iteration of the first_name:
dict = {}
for el in list:
if el in dict:
dict[el] += 1
else:
dict[el] = 1
max(dict.iteritems(), key=operator.itemgetter(1))[0] # This is your result
Enjoy :)
Upvotes: 2