User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 391,968 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,092 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser:

How to sort word (from file) frequancy in decrease order? I need help

Join Date: Jan 2008
Posts: 499
Reputation: ZZucker is on a distinguished road 
Rep Power: 1
Solved Threads: 14
ZZucker's Avatar
ZZucker ZZucker is offline Offline
Posting Pro in Training

Re: How to sort word (from file) frequancy in decrease order? I need help

  #4  
Mar 16th, 2008
... can I remove the marks like (? "" [] ) .. etc ineed only words

Instead of
word = word.rstrip('.,')
use
word = word.rstrip('.,?"[]()')

... control number of word to be enter by user

Where you now have
if n < 10:
use
if n < select:
where variable select is an integer from the user's input

... can python bult user interfac (buttun ,text box etc) and how ?

Python has a simple GUI toolkit called Tkinter supplied that can do all that for you. You need to study up on that, it's a whole new ball of wax. Here would be a typical example:
  1. # a look at the Tkinter Text widget
  2. # use ctrl+c to copy, ctrl+x to cut selected text,
  3. # ctrl+v to paste, and ctrl+/ to select all
  4.  
  5. import Tkinter as tk
  6.  
  7. def get_text():
  8. # get text widget contents between start_index and end_index
  9. # start_index = "%d.%d" % (line, column) here "1.0"
  10. # line starts with 1 and column with 0
  11. # here end_index = tk.END
  12. # set the label text to the typed-in text
  13. v1.set(text1.get(1.0, tk.END))
  14. # clear the text
  15. text1.delete(1.0, tk.END)
  16. text1.insert(tk.INSERT, ' new text')
  17. text1.insert(tk.INSERT, '\n and more text')
  18.  
  19. # this sets the window title caption too
  20. # without the leading space Text will be text!?
  21. root = tk.Tk(className = " Text, Button, Label ...")
  22.  
  23. # text entry field, width=width chars, height=lines text
  24. text1 = tk.Text(root, width=50, height=2, bg='yellow')
  25. text1.pack()
  26.  
  27. # function listed in command will be executed on button click
  28. button1 = tk.Button(root, text='get the text', command=get_text)
  29. button1.pack(pady=5)
  30.  
  31. # define a variable to hold the label text
  32. v1 = tk.StringVar()
  33.  
  34. # label text will always be the textvariable's value
  35. # width/height in char size
  36. label1 = tk.Label(root, textvariable=v1, width=50, height=2)
  37. label1.pack(pady=5)
  38.  
  39. # do some caculation and format result
  40. pi_approx = 355/113.0
  41. str1 = "%.4f" % (pi_approx) # 3.1416
  42. # show result in text widget
  43. text1.insert(tk.INSERT, str1)
  44.  
  45. # start cursor in text1
  46. text1.focus()
  47.  
  48. root.mainloop()
Last edited by ZZucker : Mar 16th, 2008 at 12:48 am.
Never argue with idiots, they'll just bring you down to their level and beat you with their experience.
Reply With Quote  
All times are GMT -4. The time now is 9:20 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC