Programming, computers, etc. [Serious]

All things asdf (and anything else)
User avatar
Dreams
ASDF High Priest
ASDF High Priest
Posts: 2306
Joined: Tue Nov 29, 2011 7:04 pm
Location: STOP STALKING ME! I'M INSECURE!
Contact:

Re: Programming, computers, etc. [Serious]

Post by Dreams » Sat Dec 03, 2011 11:16 pm

Gl, my friend.
And Computer language is a forign language! It's so freaking hard to learn!

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Sat Dec 03, 2011 11:45 pm

By "now," I meant after going to run some errands with my wife.

And I decided to increase my knowledge, so I made the Python sorter a GUI (graphical user interface). The GUI required a little research, since I haven't used Tkinter (Python's default GUI library) much at all. Luckily, Python (and most programming languages) has a built-in sorting function, so it made it relatively easy.

Here's the code. If you click "select all" and paste it somewhere, I believe it will put an extra space or tab in there. That will break the Python code, so you'll have to get rid of the first space in each line. Don't worry, it's not that long.

Code: Select all

import Tkinter

root = Tkinter.Tk()
root.title("Text sorter")

myText = Tkinter.Text(root)
myText.pack()

# e is the standard event information that gets sent to event functions. I don't really need it here, but it's going to get passed anyway.
def sortText(e):
    textToSort = myText.get(1.0,Tkinter.END).strip()
    lines = textToSort.split("\n")
    lines = sorted(lines, key = unicode.lower)
    myText.delete(1.0,Tkinter.END)
    myText.insert(1.0,'\n'.join(lines))

myButton = Tkinter.Button(root, text="Sort the Text!")
myButton.pack()
myButton.bind("<Button-1>",sortText)

root.mainloop()
Edit: Including the blank lines, that's 20 lines of code. Not bad, eh?

Also, here's a screenshot:
Text Sorter.jpg
Yay!
Text Sorter.jpg (17.34 KiB) Viewed 11861 times
Note that it handles both upper and lower case strings.
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
Dreams
ASDF High Priest
ASDF High Priest
Posts: 2306
Joined: Tue Nov 29, 2011 7:04 pm
Location: STOP STALKING ME! I'M INSECURE!
Contact:

Re: Programming, computers, etc. [Serious]

Post by Dreams » Sun Dec 04, 2011 12:05 am

Great! Now just make it ignore words in front such as the, a, and an.

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Sun Dec 04, 2011 12:07 am

Why would I want to do that?
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
Dreams
ASDF High Priest
ASDF High Priest
Posts: 2306
Joined: Tue Nov 29, 2011 7:04 pm
Location: STOP STALKING ME! I'M INSECURE!
Contact:

Re: Programming, computers, etc. [Serious]

Post by Dreams » Sun Dec 04, 2011 12:10 am

Cuz, the a and an are supposed to be ignored when alphabetizing.
That's why in the library, you see books like: Two towers, the.

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Sun Dec 04, 2011 12:12 am

Would you want me to display it like that, such as:
bit of text, A
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
Dreams
ASDF High Priest
ASDF High Priest
Posts: 2306
Joined: Tue Nov 29, 2011 7:04 pm
Location: STOP STALKING ME! I'M INSECURE!
Contact:

Re: Programming, computers, etc. [Serious]

Post by Dreams » Sun Dec 04, 2011 12:15 am

Nah, just ignore the a when you alphabetize.
Do you have an iPod?

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Sun Dec 04, 2011 12:28 am

Nope. I don't.

Here's the modified code:

Code: Select all

import Tkinter

root = Tkinter.Tk()
root.title("Text sorter")

myText = Tkinter.Text(root)
myText.pack()

def ignorer(someString):
    toIgnore = set([u'the',u'a',u'an'])
    comparer = someString.lower().split(u' ')
    if comparer[0] in toIgnore:
        #return all of the text except the first word for comparison's sake
        return u' '.join(comparer[1:])
    return u' '.join(comparer)
    

def sortText(e):
    textToSort = myText.get(1.0,Tkinter.END).strip()
    lines = textToSort.split(u"\n")
    lines = sorted(lines, key = ignorer)
    myText.delete(1.0,Tkinter.END)
    myText.insert(1.0,u'\n'.join(lines))

myButton = Tkinter.Button(root, text="Sort the Text!")
myButton.pack()
myButton.bind("<Button-1>",sortText)

root.mainloop()
I used the 'u' to indicate that they're Python Unicode strings instead of regular strings, simply because that's what the Text widget in the GUI uses. I could have left it out and it would have worked just fine.
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
Dreams
ASDF High Priest
ASDF High Priest
Posts: 2306
Joined: Tue Nov 29, 2011 7:04 pm
Location: STOP STALKING ME! I'M INSECURE!
Contact:

Re: Programming, computers, etc. [Serious]

Post by Dreams » Sun Dec 04, 2011 12:31 am

Awesome. Good job! Now I don't have to alphabetize boring stuff. Thanks so much
Also, where can I find a good android tutorial?

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Sun Dec 04, 2011 12:33 am

The Android Developer Page might be a good place to start.
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
Dreams
ASDF High Priest
ASDF High Priest
Posts: 2306
Joined: Tue Nov 29, 2011 7:04 pm
Location: STOP STALKING ME! I'M INSECURE!
Contact:

Re: Programming, computers, etc. [Serious]

Post by Dreams » Sun Dec 04, 2011 12:34 am

I looked
It doesnt HLEP!!!!!!!!!!!!!!
Don't worry. I'll find a good tutorial I like.

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Sun Dec 04, 2011 12:44 am

I haven't looked at it too in-depth, but it seems to be pretty good.

You might want to look in your library for Android books. One that I kind of liked is "Hello Android"
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
Dreams
ASDF High Priest
ASDF High Priest
Posts: 2306
Joined: Tue Nov 29, 2011 7:04 pm
Location: STOP STALKING ME! I'M INSECURE!
Contact:

Re: Programming, computers, etc. [Serious]

Post by Dreams » Sun Dec 04, 2011 12:54 am

lol you mean library as in at school?

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Sun Dec 04, 2011 12:58 am

As in the city library, probably, unless your school carries books like that.
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
Dreams
ASDF High Priest
ASDF High Priest
Posts: 2306
Joined: Tue Nov 29, 2011 7:04 pm
Location: STOP STALKING ME! I'M INSECURE!
Contact:

Re: Programming, computers, etc. [Serious]

Post by Dreams » Sun Dec 04, 2011 1:01 am

K. I'll make a journey to the main public library tomorrow or next week and get a android book.

User avatar
Dreams
ASDF High Priest
ASDF High Priest
Posts: 2306
Joined: Tue Nov 29, 2011 7:04 pm
Location: STOP STALKING ME! I'M INSECURE!
Contact:

Re: Programming, computers, etc. [Serious]

Post by Dreams » Sun Dec 04, 2011 1:13 am

Omg my first python program

Code: Select all

chucker=raw_input ('How much wood does a woodchuck chuck? ')
print chucker, 'is not the right answer. You suck.'
end=raw_input ('Press enter to continue')

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Sun Dec 04, 2011 2:24 am

Today I learned more about the Python modules Tkinter and os.

Yay! Now I can do even cooler stuff at work with my scripts!
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
Dreams
ASDF High Priest
ASDF High Priest
Posts: 2306
Joined: Tue Nov 29, 2011 7:04 pm
Location: STOP STALKING ME! I'M INSECURE!
Contact:

Re: Programming, computers, etc. [Serious]

Post by Dreams » Sun Dec 04, 2011 2:28 am

grats. what's os?

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Sun Dec 04, 2011 2:39 am

os stands for "operating system" and lets you interact more closely with your operating system. It can be powerful but confusing.
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
Dreams
ASDF High Priest
ASDF High Priest
Posts: 2306
Joined: Tue Nov 29, 2011 7:04 pm
Location: STOP STALKING ME! I'M INSECURE!
Contact:

Re: Programming, computers, etc. [Serious]

Post by Dreams » Sun Dec 04, 2011 3:19 am

confusing=not good for someone just starting python for 3 hrs.
powerful=MWAHAHAHAHAHAHAHAHAHAHAAAAAAAAA!!!!!!!!!!!!!!

Post Reply