Posts

Showing posts from August, 2009

Google friend connect in Love Python

I have added Google friend connect widget in this blog so the followers can socialize with each other. You can also do it using the 'follower' gadget. You can read about Google friend connect here: http://www.google.com/intl/en/press/annc/20080512_friend_connect.html

randomize elements in a file or list using Python

Last week I had to populate a mysql table with some random user names. First problem was to get those names - which I managed writing a crawler with Python. Using the program I got a text file with around 500 names listed in alphabetical order. But I didn't want to insert those in the same order as it will look odd (you don't want to get a list of opponent player's name all starting with 'A' in a game, right?). Then I decided to write some python code to generate another file with names in random order. The logic will be simple. First load all the names in a list, and from that list get a random element and put in another list. Delete the element from the initial list. Before I started coding, I googled for a while and found an interesting solution! import random ... count = names.__len__() # names is the list containing names in alphabetical order names = random.sample(names, count) # now names contain names in random order! ... Another Python magic!