Python from scratch – lists My journey into Python from scratch got into the list phase. But it started with a crazy week Crazy week Well, I had a crazy week. My first post- Python from scratch was a huge hit. I got all this attention and even now a few days later I still get visits and comments and being followed by Email and RSS. I have read each comment and each referral to a site which led me to many python sites that come to help and found myself in heaven for a newbie like me. Also, I met this guy from Costa-Rica who is going through the same journey more or less like me and we are exchanging ideas by email.

The success of the first post

My post was published on some great sites and if you search in Google “python from scratch” I am on top5. All the above made me lose focus and on top of it my young son got sick (still) so I had some sleepless night lately. Last night I decided that no matter what I will continue on my journey and I have started to read the next page in Google python class- lists .

Python from scratch – learning lists

So I read the entire chapter which teaches how lists work in Python, a bit tricky in some points yet easy to follow. Then the chapter teaches how to use the FOR var IN list which is different from C++ It took me some time to get used to it but once you get it- wow! Towards the end, you get familiar with some lists method which will come handy later on and voila- the exercise.

First problem

So here I am solving the tests and the first 2 problems I was doing fine only to bump into the third problem which took me around an hour, here it is: “Given a list of non-empty tuples, return a list sorted in increasing order by the last element in each tuple.” example- (1, 3), (3, 2), (2, 1) should return- (2, 1), (3, 2), (1, 3). Easy to see the obstacle over here is how to sort using the last elementץ I really tried to make my code as simple as possible (KISS). But no matter what I did I was writing more and more rows and more and more taking care of corner cases Until I decide that I am doing something wrong and surely there is a faster solution hidden in the learning subject.





Does Google have a bug?

So I read the lists page course again until I discovered the problem- Google has a Doc BUG in this page- an important method is mentioned but not explained. It says: list.sort() — sorts the list in place (does not return it). (The sorted() function shown below is preferred.) But there is no sorted() below and this method was the method to solve the issue easily. in fact, also list.sort() can handle this case but I couldn’t understand it from reading over here. After spending too much time on this and being so late at night I went to sleep.

Easy to solve

The night follows I spent another 30 minutes to solve the advanced exercise and again I met into a strange situation. The second exercise was very easy to do and took me only 3 rows to complete. Yet Google solution was about 10 rows (not making sense, haha)

Ask the experts