python0926 - dictionary -- uses { }, index notation uses [...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
a = [1,2,3] ##is a list b = (1,2,3) ##is a tuple cannot support item assignment/can't be changed functions: len(x), abs(x) f (x,y,z) x.upper(c) Regular expressions : import re has diff components; re.match ##finds a match for a pattern in the beginning of a string string.'reg ex',string) ## finds a match for a pattern in a string (r'regex',string, re.I) ellimates case difference. re.sub(r'reg ex', string1,string2) ##replaces everything in the first string that matches in the reg ex with the second string reg ex sys.argv[1] the first thing after the command [0] in the unix command line
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: dictionary -- uses { }, index notation uses [ ] has to be a immutable object (not a list), value can be anything. types={} for token_string.split(): *** type[token] = types.get(token.0) + 1 *** dict.keys() .values() In order to sort by values rather than keys, we may use .items() which will give us a list of tuples with pairs of keys/values Would like to sort by values and get out the keys sorted() options: (seg,key=give a function here which will tell it where in the function it should be sorted by)...
View Full Document

This note was uploaded on 09/06/2009 for the course LING 571 taught by Professor Staff during the Fall '08 term at San Diego State.

Ask a homework question - tutors are online