How to write a binary search that looks for words in a list
Question: I was wondering how to write a binary search that looks for the most popular
baby names from 2009 - 2014, the names are stored in a list and then I when I
receive a prompt asking for what i would like to search for then i would type
in the name and it would give how many times it iterated over to find the
certain name, and also the names are in JSON format and alphabetical so i can
compare characters.I'm planning to write this in python 3. Any help would be
greatly appreciated.

    
    
    termToFind = input("What would you like to find? ")
        tempMeds = []
    for me in allMeds:
       if len(me) >= len(termToFind):
       tempMeds.append(me)
    findLength = len(termToFind)
    currentPos = len(tempMeds) // 2
    stop = False
    iterations = 0
    amountFound = 0
    prevVal = ""
    


Answer: Why do you need to use a binary search? What if you used
[`collections.Counter`](https://docs.python.org/3/library/collections.html#collections.Counter)?

Just pass your list (doesn't matter if it's sorted or not) of baby names to
`Counter` and then lookup whatever name you're interested in:

    
    
    import json
    from collections import Counter
    
    json_baby_names = '["aardvark", "apple", "apple", ...., "zeus"]'
    baby_name_counts = Counter(json.loads(json_baby_names))
    
    >>> baby_name_counts['apple']
    2
    

If you want the most popular name, you can use `Counter.most_common()`:

    
    
    >>> baby_name_counts.most_common(1)
    [('apple', 2)]
    

