It is not nice to name yourself as your favorite programmer, this is not modest at all and that way you are telling us you are the best programmer ever, which is irritating. We have a Bulgarian proverb "Modesty makes the person pretty", you should look it up. And that guy KJGino agreed with you, which makes him guilty too.
It's OK to have self confidence, but it is not OK to throw it into the people's noses.
Thank you for your rebuttal but just because you disagree with someones opinion does not mean it is not "helpful" thus down voting was childish of you, something they used to do on YouTube comments..
However If you read my first response I did say I chose myself as I believe it is good to believe in yourself I did also express I did not mean it in an egotistical way thus I actually agreed with you straight from the start.
Further more just because they are your favourite programmer does not mean they have to be the best, my favourite athlete is not the best yet she has shown consistent drive and determination in life also she has never given up, each year she attempts to win again and again.
I have no doubts you will down vote this post as it does not agree with you and that does not bother me as I don't need to validate my life by your acceptance, I do however implore you to take this discussion private as not to derail the thread any further with any person issues you may have with me.
As egotistical as this sounds, one of my favourite programmers is in fact myself alongside, KJGino, Bill Gates, Grace Hopper and most of you guys, simply because you all help contribute to the modern day programming world in some way, I choose myself not out of ego or arrogance but because I'm a strong believer in believing in yourself so that's why I like myself as a programmer.
Personally it's the opposite, the more time I spend away from my computer the less programming I feel I'm able to do! My creativity flourishes more when I'm working but I guess that's because of how intense I usually am with education.
Now I know some people have different religions and thus they do not celebrate Christmas however I figured I would start a topic and ask everyone what their plans are? Are you a sociable person who visits lots of family and has a house full of decorations or are you like me and just want to eat lots of food and ignore the world for a day?
P.S. If you don't celebrate Christmas, what do you celebrate? This way we can all get to know each other a bit better.
This is one of the few things that I actually remember from Python. It is called Extended Slices. The syntax for it is: [start:end:step]
Start is the first character position in the string you are working with, so if you had [1::] it would start with the char at the index 1 position, and since no end point is defined, it would go to the end of the string.
If you had [1:4] - it would start with the position 1 and go to the 4th position (but NOT include the 4th position, so in essence 1 through 3).
If you include a step, then you could do something like this: [1:4:2] would output every other char in the string, from position 1 to position 4, but not including the char at position 4.
To explain what LKP did - she left the beginning and end undefined so that the whole string would be used, and since the step was -1, it iterated through the string in reverse. So, [::-1] would give you the output of the whole string in reverse.
See here for more detailed information on Extended Slices.
KJGino explained that rather well, thank you however he also forgot his cardinal numbers. So the start of the string would be 0 instead of 1.
This is a nice little trick/exercise, as a result I attempted it in Java, and would be interested to see your one line solution. Here is one that I wrote, however; it is written in Java (however, should easily be translatable)
return isPalindrome = new StringBuilder(stringHere).reverse().toString().equals(stringHere);
This is a very simple Palindrome checker in Python I just wrote it because I had never wrote one before, it was a lot simpler than I thought it would be (luxury of Python).
What is a Palindrome?
A Palindrome is a word that is the same when it is reversed for an example if I said "Cat" is a palindrome it is not because if you reverse it, it spells taC however if we have something like "Dad" in reverse it still spells "daD" so this is a palindrome.
print "What is the word you would like to check?" # Asks the user what word they would like to check.
x = raw_input("> ") # User inputs the word.
y = x[::-1] # reverses the string.
if x.lower() == y.lower(): # checks if the strings match, this way it handles case sensitivity.
print x,"is a palindrome!" # prints it is a palindrome
else: # and if it's not a palindrome
print x,"is not a palindrome!" # it will print it is not a palindrome!
This is my Python Scraper, I won't include the counter part (my PHP document that renders it) however you can find it on my Pastebin which is HERE or you can find a link to it in the script.
NOTE: The PHP script is NOT commentated as this post is about my Python Script and NOT my PHP rendering also note there is NO css file to go with it.
# Python Reddit Scraper V1.0
# PHP XML Render page: http://pastebin.com/nip125AJ
# This script scrapes Reddit
# It then exports it to an XML file to be read whichever method you decide is best.
# I wanted to create a scraper that would grab three things 1. The name of the post 2. The comments section URL and 3. The image / youtube video attributed to the post
# Coded on Python 2.7.5
# Requires Requests and LXML modules
# Coded by LKP from CodeCall.net
# Pastebin: http://pastebin.com/u/LorenKPetrov
# IMPORTS #
from lxml import html # Imports HTML from LXML
import xml.etree.cElementTree as XMLT # Imports element tree for python so it can write XML in the right style.
import requests # imports the requests so Python can
# VARIABLES #
page = requests.get('http://www.reddit.com/r/minecraft') # Gets the page to scrape
tree = html.fromstring(page.text) # converts the HTML page into a tree for XPATH to read
title = tree.xpath('//a[@class="title "]/text()') # Grabs the Hyperlink text with the class named title NOTE: The space is supposed to be there, on Reddit the space is still there.
link = tree.xpath('//li[@class="first"]/a/@href') # Similiar to above but grabs the Hyper link from the href tag from the li tag with the class "first".
imgur = tree.xpath('//p[@class="title"]/a/@href') # and again with above it grabs the href tag within the paragraph tag.
root = XMLT.Element("ENTRY") # This is my root XML tag so it doesn't become part of the loop
start = 0 # This number was what I used during my While tag.
total = len(title) # This counts the total of entries, to explain that a bit clearer if we liken it to a book, it's like counting the number of chapters in a book, I.e. 36 chapters.
# MAIN CODE #
while start < total: # While start (equal to 0) is less than the total (equal to however many variables are in the title list) do the following
doc = XMLT.SubElement(root, "POST") # Writes the XML tag POST
field1 = XMLT.SubElement(doc, "TITLE") # Writes the XML tag TITLE
field1.text = title[start] # Writes the tag content for TITLE
field2 = XMLT.SubElement(doc, "MEDIA") # Writes the XML tag MEDIA
field2.text = imgur[start] # Writes the tag content for MEDIA
field3 = XMLT.SubElement(doc, "LINK") # Writes the XML tag LINK
field3.text = link[start] # Writes the tag content for LINK
start = start + 1 # Adds 1 on to the variable 'start' so it will loop the code for the amount of times that the total is less than the start
tree = XMLT.ElementTree(root) # Makes the ENTRY tag in the XML document
tree.write("MC.xml") # finally, it writes the info to the specified XML document.
I have commented on the code, it's a very simple time scraper!
# Time grabber by LKP
# Python Version 2.7
# Requires LXML
from lxml import html
print "Which country would you like to know the time of?" # Asks the user which country they would like to know the time of.
country = raw_input("> ") # Country variable
replacement = country.replace(" ","_") # If you enter in a country like "United Kingdom" the website TheTimeNow.com requires an underscore in its URL i.e. http://www.thetimenow.com/United_Kingdom so this replaces a "space" in the two words meaning it doesn't error.
page = requests.get("http://www.thetimenow.com/"+replacement) # Gets the entire page
tree = html.fromstring(page.text) # Converts it into a simple tree for LXML to read
time = tree.xpath('//span[@id="main_time"]/text()') # Reads the Span tag with the ID "main_time"
print "The current time in",country,"is",time # Prints the users selected country along with the current time including PM/AM
# Simple Interest Calculator
# Only works in Dollars and does not handle Cents
# By LKP
# Spelling mistakes may be rampant.
# Has no error handling but still figured it would be fun to do
# Based off of the mathematics problem from this post
print "What is your savings amount?" # Queries the amount of savings
savings = raw_input("> ") # sets the savings variable from the users input
print "What is your yearly interest rate?" # Queries the amount of interest in Percent
interest = raw_input("> ") # Sets the interest variable
print "How much will you withdraw per year?" # queries the amount that will be widthdrawn per year
withdraw = raw_input("> ") # Sets the withdraw variable
trim_s_one = savings.replace("$","") # Takes the dollar symbol off of the input (only if it exists)
trim_s_two = trim_s_one.replace(",","") # Takes the commas off the input
savings_conv = int(trim_s_two) # turns the string into an interger
trim_i_one = interest.replace("%","") # takes off the % sign from the interest variable
interest_conv = int(trim_i_one) # Converts it into an interger too
trim_w_one = withdraw.replace("$","") # Again, takes the dollar sign off of the withdraw variable
trim_w_two = trim_w_one.replace(",","") # Takes the commas off too!
withdraw_conv = int(trim_w_two) # And again converts it into an interger
B =  # List to append
while savings_conv > withdraw_conv: # while the savings is greater than the widthdraw then loop the code!
savings_conv = savings_conv - withdraw_conv # repeatedly subtracts from the savings interger
interest_generated = savings_conv / 100 * interest_conv # works out how much interest has been accumulated.
savings_conv = savings_conv + interest_generated # Adds the accumulated interest into the savings
B.append(str(savings_conv)) # adds each amount of withdrawls to the list
# This code then counts the amount of variables in the list and that's how many years it will last!
print "You can withdraw $"+withdraw,"for",len(B),"years before your account will be left with $"+B[-1],"left!"
It's not perfect, could have refined the code but I figured it would be a fun thing to do whilst I had a few minutes to spare.
First of all, it is hard to say what will be useful in 20 years time, we can only give you an estimate not a guarantee however anything you do with technology will be 'useful' so long as you keep up with the changes in it (such as Python going from 2.X to 3.X) and learn how to adapt to the new way things run, always learn new programming things, technology is evolving fast and it requires a fast and adaptive nature to keep up with it.
I would focus on learning one language at a time and go from there, Java, Python and C++ are good languages to know for software and PHP/Python is my personal favourite for anything website related.