Live data from Hacker News

Offer HN: I'll help you learn Python

news.ycombinator.com

21–30 of 51 posts

Re: Offer HN: I'll help you learn Python

#22
post #16

I've been trying to get an answer to my Python question: http://news.ycombinator.com/item?id=1841536 Maybe you can take a look at that?

Looks to me like you're trying to shoehorn everything into the one list, which is going to make your code hard to write. Something to note is that you're adding blank strings ('') to your list to pad it out, which is a bit of a warning sign that your data structure is wrong. Rather than do that, I'd use a dictionary keyed off either an id or the original text, store the user input as a list after that, then sort out…

Thanks. I am sorry that my question is not clear. In this case, the user enters a string s in a form and I append that to an empty list L = [] then I test if the last saved string is the same as the new string. If same, I write it on the same column; if not the cursor moves to next column (I was trying to do this with tables) and as long as the user types the same string the cursor stays on the same column. If a new string is typed; a new column is started; and so on.

In your example, if I understand correctly; it is assumed that there is a list of 3 "Hello World"s. In reality, each should be entered and then displayed (I use Mako templates).

This looks like a simple problem but I was unable to make it work. Thanks again.

Re: Offer HN: I'll help you learn Python

#23
post #22

Earlier quoted context omitted.

Looks to me like you're trying to shoehorn everything into the one list, which is going to make your code hard to write. Something to note is that you're adding blank strings ('') to your list to pad it out, which is a bit of a warning sign that your data structure is wrong. Rather than do that, I'd use a dictionary keyed off either an id or the original text, store the user input as a list after that, then sort out…

Thanks. I am sorry that my question is not clear. In this case, the user enters a string s in a form and I append that to an empty list L = [] then I test if the last saved string is the same as the new string. If same, I write it on the same column; if not the cursor moves to next column (I was trying to do this with tables) and as long as the user types the same string the cursor stays on the same column. If a new…

I was just showing you what the data structure to store your text might look like. In practice there are a number of ways to do it, but you should be guided by what'll make it easiest to get your data out. In other words, you might be able to make it work with a list of lists, but you're trying to cut 'across' the list, rather than with it. So with your existing list:

list = [ ['Hello World', 'Hello World'], ['Hello Universe', ...], ... ]

you'll need to display the first item of each on one row, then the second, and so on, which is a hassle.

Another way might be to pregenerate your list of lists with blank items (assuming that you know how many different strings you have and how many tries they get) then track the current row and column number. If they enter it successfully then your current row increments by one. If they choose a different one, then increment your column and reset

But you seem to be overly focused on the details of your implementation (ie. rows and columns), rather than the simplest way to achieve what you want. A third way would be to have each series on a separate page, so you only need to track the current string. Once they're ready, they can click a button to get to the next one/enter a new string.

A fourth way - don't use a table, use with a set width and display-inline. Each has the previous entries separated by line breaks, with a form for the final one. With this sort of structure you can process each list in turn, without having to worry about indexing.

Re: Offer HN: I'll help you learn Python

#24
post #19

My question is: I don't know any Python and would like to start learning it. Should I bypass Python2 altogether and start with Python3 or stick with Python2?

If you would like to use App Engine (great & free!), then stick with Python 2.5 for now.

Or pretty much any other major Python library or framework - Django or Twisted, for instance.

Re: Offer HN: I'll help you learn Python

#26

Plug: I'm just in the final stages of finishing an introductory Python book, Hello! Python: http://manning.com/briggs/ . It's a bit different, in that I'm using real world projects (Hunt the Wumpus, Django, web scraping, writing games) to demonstrate how to program, rather than just having a laundry list of features and stepping through them one by one. Think of it as Land of Lisp , but in Python rather than CL.

That's a great idea. I've thought of writing something like that myself, but with a focus on learning Django (for people who already know Python.)

Do you think there is any interest in such an ebook?

Re: Offer HN: I'll help you learn Python

#27
post #19

My question is: I don't know any Python and would like to start learning it. Should I bypass Python2 altogether and start with Python3 or stick with Python2?

You should definitely learn Python 2. Almost all libraries still are on 2, so if you tried to go straight to 3, you'd have to struggle your way around most newbie documentation on the internet - Especially if you're planning on doing Django work.

Anyway, there isn't a whole lot of difference between python 2 and 3, really. The "proper" way of coding in python2 is very similar to python3.

Re: Offer HN: I'll help you learn Python

#28

Plug: I'm just in the final stages of finishing an introductory Python book, Hello! Python: http://manning.com/briggs/ . It's a bit different, in that I'm using real world projects (Hunt the Wumpus, Django, web scraping, writing games) to demonstrate how to program, rather than just having a laundry list of features and stepping through them one by one. Think of it as Land of Lisp , but in Python rather than CL.

I took a quick look. As its a paid-book I think it would be useful to have at least one of the exercises open for people to see. I appreciate the introduction is available to download, but the real-world projects aren't (and I understand why) but my suggestion would be to open one of them so that we can see what kind of exercises in real life

Re: Offer HN: I'll help you learn Python

#29
post #26

Plug: I'm just in the final stages of finishing an introductory Python book, Hello! Python: http://manning.com/briggs/ . It's a bit different, in that I'm using real world projects (Hunt the Wumpus, Django, web scraping, writing games) to demonstrate how to program, rather than just having a laundry list of features and stepping through them one by one. Think of it as Land of Lisp , but in Python rather than CL.

That's a great idea. I've thought of writing something like that myself, but with a focus on learning Django (for people who already know Python.) Do you think there is any interest in such an ebook?

I would imagine so - although there's a fair bit of Django documentation out there, so you'd need some sort of point of difference in order to compete.

If you're serious about it I can put you in touch with someone at Manning. They're always looking for new authors and reviewers.

Post reply on HN