Python Challenge Level 2

I am trying to solve Python challenges in pythonchallenge.com. I am in level 2. I was asked to find rare characters in a very large text which is given in the source code of the web page. Here it is: http://www.pythonchallenge.com/pc/def/ocr.html

First of all, I don't want any solutions for this. I just want to solve it on my own but I am not an advanced Python programmer. So can you tell me what to study to solve this? I also don't know how to work with files very well. In some clues on forum, it is mentioned that one should use files to solve this. So can you show me what to study?

Answers


Hint 1: To open and read a file's contents, use

with open("filename") as f:
    contents = f.read()

Hint 2: To count characters, one option is to use a Counter.


First of all, read all the characters into a string. You can use urllib2 to download the file, open to read it from the local disk, or hardcode its contents. To include such a long string your Python program, you may want to use triple-quotes strings, as in:

"""
%%$@_$^__#)^)&!_+]!*@&^}@[@%]()%+$&[(_@%+%$*^@$^!+]!&_#)_*}{}}!}_]$[%}@[{_@#_^{*
@##&{#&{&)*%(]{{([*}@[@&]+!!*{)!}{%+{))])[!^})+)$]#{*+^((@^@}$[**$&^{$!@#$%)!@(&
...
"""

To find out the number of occurences of each character, have a look at collections.Counter.


Use Counter from collections to count the number of occurences of each to character to find the 'rare' characters.

I'll leave the rest for you to figure out after you view the results of the count.


Need Your Help

Why the form class in windows form application is declared as partial?

c# .net winforms forms

Can somebody tell why and for what it is declared as partial?