On Wed, Jan 23, 2013 at 1:55 AM, Ferrous Cranus <nikos.gr...@gmail.com> wrote: > I insist, perhaps compeleld, to use a key to associate a number to a filename. > Would you help please? > > I dont know this is supposed to be written. i just know i need this: > > number = function_that_returns_a_number_out_of_a_string( > absolute_path_of_a_html_file) > > Would someone help me write that in python coding? We are talkign 1 line of > code here....
def function_that_returns_a_number_out_of_a_string(string, cache=[]): return cache.index(string) if string in cache else (cache.append(string) or len(cache)-1) That will work perfectly, as long as you don't care how long the numbers end up, and as long as you have a single Python script doing the work, and as long as you make sure you save and load that cache any time you shut down the script, and so on. It will also, and rightly, be decried as a bad idea. But hey, you did specify that it be one line of code. For your real job, USE A DATABASE COLUMN. ChrisA -- http://mail.python.org/mailman/listinfo/python-list