data structures - Programming concept -


i want make program sort mail junkmail using point--system.

for couple of words in mail,
want program give different points each word have in program categorized "junkwords" have assign different points different words, each word worth amount of points.

my pseudocode:

  1. read text file
  2. look "junk words"
    • for each word comes give point word worth.
  3. if total points each junkword 10 print "spam" followed list of words in file , categorized junkwords , points.

example (a textfile):

hello!   have trouble sleeping?  need rest? dont hesitate call absolute solution- without charge! 

so when programs run , analyzes text above should like:

spam 14p trouble 6p charge 3p  solution 5p  

so planing write in manners:

class junk(object):     fil = open("filnamne.txt","r")     junkwords = {"trouble":"6p","solution":"3p","virus":"4p"}     words = junkwords      if words in fil:         print("spam")     else:         print("the file doesn't contain junk") 

so problem how give points each word in list comes in file?
, how sum total points if total_points > 10 program should print "spam",
followed list of 'junkwords' found in file , total points of each word..

here quick script might close there:

maxpoints = 10 junkwords={"trouble":6,"solution":5,"charge":3,"virus":7} fil = open("filnamne.txt", "r")  foundwords = {}  points = 0  word in fil.read().split():    if word in junkwords:        if word not in foundwords:            foundwords[word] = 0        points += junkwords[word]        foundwords[word] += 1  if points > 10:     print "spam"     word in foundwords:         print word, foundwords[word]*junkwords[word] else:     print "the file doesn't contain junk" 

you may want use .lower() on words , make dictionary keys lowercase. maybe remove non-alphanumeric characters.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -