Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Python

Name: Anonymous 2011-01-23 14:50

Newbie to Python here

I made a function that calculates distribution of certain characters in any given text file and saves them in another *.txt file like so 'character' + '\t' + percentage + '\n'
And now I'm trying to write the characters and their distribution percentages from that *.txt file to a new dictionary which takes the character as keys, and percentages as values.

I can't figure out how to transfer the files from that document to the dictionary...

to visualize:

def read_dist(filename):
dictdist={}
#### This part here ####
return dictdist

Name: Anonymous 2011-01-23 14:54

DOUBLE WORD: 0x8FFFFFFF. THREAD OVER

Name: Anonymous 2011-01-23 14:54

The main issue here is the lack of code tags.

Name: Anonymous 2011-01-23 14:58

Come on give me a fucking break

Name: Anonymous 2011-01-23 14:58

>>1

with open(filename, 'r') as f:
   for s in f:
      s = s.strip()
      if not s: continue
      c, p = s.split('\t')
      dictdist[c.strip()] = float(p)


Now go away and never come back, I wouldn't even lecture you on the subject of using [code] tags.

Name: Anonymous 2011-01-23 15:02

>>3,5
Lack of [code] tags?
He didn't [spoiler]indent his [spoiler][b]FIOC[/b][/spoiler] code[/spoiler].

Name: Anonymous 2011-01-23 15:07

>>5
Well thanks I guess
Only thing is that I can't use .strip() because the character cluster may start with a space. All I really need to remove are the '\n' next line commands.

Name: Anonymous 2011-01-23 19:06

Lack of [code] tags?
He didn't indent his FIOC code.

Name: Anonymous 2011-01-23 19:12

>>7

Then .rstrip("\n")

Name: Anonymous 2011-01-24 7:33

Somebody, tell >>1,4,7-8 that here it's a bad manner to not fill email field with noko

Name: Anonymous 2011-01-31 19:44

<-- check em dubz

Name: Anonymous 2011-02-03 7:30


Don't change these.
Name: Email:
Entire Thread Thread List