Tuple unpacking

Unpacking a tuple means giving a different name to each element of the tuple. Tuple unpacking is useful because many functions in Python, such as the zip function described in the previous Building lists incrementally section, return tuples. With tuple unpacking, you can easily get at the individual items in these tuples. To unpack a tuple, just assign multiple names on a single line. Put the names you want to unpack into on the left side of the assignment statement and put the tuple on the...

Getting Close Enough with difflib

People often make mistakes when entering text. The difflib module gives you a way to find strings that are close but not exact matches to a given string gt gt gt right 'The quick brown fox' gt gt gt wrong 'THe quack brown fix' gt gt gt matcher difflib.SequenceMatcher None, right, wrong The ratio method returns a floating point number between 0 and 1 that indicates how close the match is. Higher numbers indicate a closer match. A match higher than 0.6 is usually considered good maybe not by...

Debugging in IDLE

When you run code in IDLE's interactive mode, it informs you of errors the same way you've seen when using interactive mode in a Terminal or shell window. When you run code from the text editor, IDLE also informs you of errors. Depending on the kind of error and on your version of IDLE, the error message appears in a dialog box or in the Python Shell window. You can use the IDLE debugger to step through your program in various ways and display the values of names. The IDLE debugger is shown in...