Find most frequent phone number from given .txt file
<p>For example: 
me.txt (which conatains data as well as phone numbers)which has below info</p>

<pre><code>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

1.Phone number 1: (999) 999-3333
2.phone number 2: (888) 999 -2212
3.Phone number 3: (111) 222 - 2223
4.Phone number 4: (999)999-3333
5.Phone number 5: (888)222-2222
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

6.Phone number:  (999)999-3333
</code></pre>

<p>so the <strong>o/p</strong> should be : (999)999-3333 - 3 times </p>

<p>My try:</p>

<pre><code>txtFile = urllib.urlopen("http:// me.txt").readlines()
txtFile = "".join(char for char in txtFile if char.isdigit()) #removes everything that's not numeric.

phone_counter = {}
for phone in txtFile.split(" "): # split in every space.

    if len(phone) &gt; 0 :
        if phone not in phone_counter:  
            phone_counter[phone] = 1
        else:
            phone_counter[phone] += 1

for i,phone in  enumerate(sorted(phone_counter,key=phone_counter.get,reverse=True)[:-1]):
    print "%s: %s - %s"%(i+1,phone,phone_counter[phone])
</code></pre>

<p>This way I can't read numbers .Looking for <strong>python</strong> solution</p>

<p>Your text file seems to have some non-related stuff around it. Taking just the numbers will make the numbers unreadable as they are merged with random numbers in the text.</p>

<p>Since I can't tell the exact format of the phone numbers on a line, you can use a regex to extract the number from a line.</p>

<p>You can also use a <code>collections.Counter</code>, as in the above answer.</p>

<pre><code>import re
from collections import Counter

NUMBER_RE = re.compile(r'\((\d{3})\)\s?(\d{3})\s?-\s?(\d{4})')
                     #    \d{3} = 3 digits
                     #       \s? = optional space

def format_number(re_match):
    """Makes sure that the spacing is consisten to count them properly"""
    return '({0[0]}) {0[1]} - {0[2]}'.format(re_match)

txtFile = urllib.urlopen("http:// me.txt").readlines()

counter = Counter()
for line in txtFile:
    for match in NUMBER_RE.findall(line):
        counter[format_number(match)] += 1

most_common = counter.most_common(1)[0]
print("'{0[0]}' appears {0[1]} times.".format(most_common))
</code></pre>

python