My friend Aleksi started a blog few months ago about Linux and programming etc. Please check it out here FWFAILL

Because he has been learning Java and I found my inner Python fanboy, we decided to compare some source codes to see how some programming languages differ from each other.

Here are some first results on comparing Python and Java!

Python: count how many times specified line appears in file

Mission: I have a txt file which includes several hundred email addresses. One address per line. I want to calculate how many times each address occure in the file.

Example list:
address1@example.com
address1@example.com
address2@example.com
address3@example.com

Solution:
address1@example.com appears 2 times
address2@example.com appears 1 time
address3@example.com appears 1 time

There are easy ways to do this ie from Linux command line, but we are here to learn and make geekstuff so I wanted to do it in Python.Here is the whole Python code in .txt file. There might be more faster/easier/nicer = Pythonic way to do this but optimization was not the first goal!

Check Aleksis blog for his Java based answer to the problem!

Kommentit

Kommentoi

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.