Anish Menon
Anish Menon

Reputation: 809

Find the Common first_name from Django Auth user Model

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

Answers (1)

abrunet
abrunet

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

Related Questions