PDA

View Full Version : [SOLVED] [Python] python challenge 2



TreeFinger
July 10th, 2008, 08:30 PM
no cheating


I added the 'print lineCount' for debugging.

my program doesn't move to line 2.. at least not for as long as i ran it which was a good 5 minutes. What do I need to do?

info for anyone unfamiliar with this challenge..

got a text file with a large large amount of lines.
example of a line: }!)$]&($)@](+(#{$)_%^%_^^#][{*[)%}+[##(##^{$}^]#&(&*{)%)&][&{]&#]}[[^^&[!#}${@_(

Need to find characters that occur a very few amount of times.

WW
July 10th, 2008, 09:10 PM
++i doesn't work in Python; try i += 1.

Lster
July 10th, 2008, 09:20 PM
I'm not quite sure what you're trying to do there. The clue is that you need to shift each character 2 places forward in the alphabet. I have working code if you want to see it (likely spoilers).

archivator
July 10th, 2008, 09:36 PM
This is hardly Pythonic and your approach has multiple problems associated with it.

1. A dictionary should not be called dict. dict is built-in type and you might have troubles this way.
2. What's that `dict' doing at the end? Are you using python < script.py ?
3. You're using a C-ish approach to reading a file and it's .. well, wrong.


File = open("string.txt")
for line in File:
print line

Much better, isn't it?
4. String are sequences.


for char in line:
print char


I think you can figure the rest by yourself :)

TreeFinger
July 11th, 2008, 02:26 AM
thank you all for the replies :)

first day programming in python and your guys tips helped me out a lot.

got the answer rather quickly after reading your posts.

could you guys check out my new program and tell me if there is anything not needed??



no cheating

WW
July 11th, 2008, 02:42 AM
line [i]is char, so you can replace each occurrence of line[i] with char; there is no need for the variable i.

ghostdog74
July 11th, 2008, 03:03 AM
data = open("file").read()
print [ (i,data.count(i)) for i in set(list(data))

Luggy
July 11th, 2008, 05:50 AM
I stumbled across the same challenge!

My solution was 9 lines big, that's pretty heafty compared to the solutions but granted that I had no idea what I was looking for I think it is still good.

I've attached my solution in case you need some help, or if anyone else wants to look.

TreeFinger
July 11th, 2008, 12:43 PM
alright, all done.



no cheatin