''' # Define a procedure, add_to_index, # that takes 3 inputs: # - an index: [[<keyword>,[<url>,...]],...] # - a keyword: String # - a url: String # If the keyword is already # in the index, add the url # to the list of urls associated # with that keyword. # If the keyword is not in the index, # add an entry to the index: [keyword,[url]] index = [] def add_to_index(index,keyword,url): new_list = [keyword, [url]] # If the keyword is already # in the index, add the url # to the list of urls associated # with that keyword. if keyword in index: #append to position of [keyword] + 1? index[index.index(keyword)][0] + url # If the keyword is not in the index, # add an entry to the index: [keyword,[url]] if keyword not in index: index.append(new_list) add_to_index(index,'udacity','http://udacity.com') add_to_index(index,'computing','http://acm.org') add_to_index(index,'udacity','http://npr.org') print index #>>> [['udacity', ['http://udacity.com', 'http://npr.org']], #>>> ['computing', ['http://acm.org']]] ''' print 'hello world'
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question