Programming, computers, etc. [Serious]
- Dreams
- 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]
Gl, my friend.
And Computer language is a forign language! It's so freaking hard to learn!
And Computer language is a forign language! It's so freaking hard to learn!
- Anonymously Famous
- JKL; Assassin
- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
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.
Edit: Including the blank lines, that's 20 lines of code. Not bad, eh?
Also, here's a screenshot: Note that it handles both upper and lower case strings.
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()
Also, here's a screenshot: Note that it handles both upper and lower case strings.
BOTTOM TEXT
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- Dreams
- 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]
Great! Now just make it ignore words in front such as the, a, and an.
- Anonymously Famous
- JKL; Assassin
- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
Why would I want to do that?
BOTTOM TEXT
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- Dreams
- 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]
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.
That's why in the library, you see books like: Two towers, the.
- Anonymously Famous
- JKL; Assassin
- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
Would you want me to display it like that, such as:
bit of text, A
BOTTOM TEXT
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- Dreams
- 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]
Nah, just ignore the a when you alphabetize.
Do you have an iPod?
Do you have an iPod?
- Anonymously Famous
- JKL; Assassin
- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
Nope. I don't.
Here's the modified code:
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.
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()
BOTTOM TEXT
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- Dreams
- 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]
Awesome. Good job! Now I don't have to alphabetize boring stuff. Thanks so much
Also, where can I find a good android tutorial?
Also, where can I find a good android tutorial?
- Anonymously Famous
- JKL; Assassin
- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
The Android Developer Page might be a good place to start.
BOTTOM TEXT
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- Dreams
- 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]
I looked
It doesnt HLEP!!!!!!!!!!!!!!
Don't worry. I'll find a good tutorial I like.
It doesnt HLEP!!!!!!!!!!!!!!
Don't worry. I'll find a good tutorial I like.
- Anonymously Famous
- JKL; Assassin
- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
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"
You might want to look in your library for Android books. One that I kind of liked is "Hello Android"
BOTTOM TEXT
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- Dreams
- 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]
lol you mean library as in at school?
- Anonymously Famous
- JKL; Assassin
- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
As in the city library, probably, unless your school carries books like that.
BOTTOM TEXT
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- Dreams
- 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]
K. I'll make a journey to the main public library tomorrow or next week and get a android book.
- Dreams
- 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]
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')
- Anonymously Famous
- JKL; Assassin
- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
Today I learned more about the Python modules Tkinter and os.
Yay! Now I can do even cooler stuff at work with my scripts!
Yay! Now I can do even cooler stuff at work with my scripts!
BOTTOM TEXT
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- Dreams
- 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]
grats. what's os?
- Anonymously Famous
- JKL; Assassin
- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
os stands for "operating system" and lets you interact more closely with your operating system. It can be powerful but confusing.
BOTTOM TEXT
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- Dreams
- 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]
confusing=not good for someone just starting python for 3 hrs.
powerful=MWAHAHAHAHAHAHAHAHAHAHAAAAAAAAA!!!!!!!!!!!!!!
powerful=MWAHAHAHAHAHAHAHAHAHAHAAAAAAAAA!!!!!!!!!!!!!!