Skip to Content
Head First Python
book

Head First Python

by Paul Barry
November 2010
Beginner
494 pages
10h 52m
English
O'Reilly Media, Inc.
Content preview from Head First Python

Chapter 6. Custom data Objects: Bundling code with data

image with no caption

It’s important to match your data structure choice to your data. And that choice can make a big difference to the complexity of your code. In Python, although really useful, lists and sets aren’t the only game in town. The Python dictionary lets you organize your data for speedy lookup by associating your data with names, not numbers. And when Python’s built-in data structures don’t quite cut it, the Python class statement lets you define your own. This chapter shows you how.

Coach Kelly is back (with a new file format)

image with no caption

The output from your last program in Chapter 5 was exactly what the coach was looking for, but for the fact that no one can tell which athlete belongs to which data. Coach Kelly thinks he has the solution: he’s added identification data to each of his data files:

image with no caption

If you use the split() BIF to extract Sarah’s data into a list, the first data item is Sarah’s name, the second is her date of birth, and the rest is Sarah’s timing data.

Let’s exploit this format and see how well things work.

Do this!

Grab the updated files from the Head First Python website.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Head First Python, 2nd Edition

Head First Python, 2nd Edition

Paul Barry
Dead Simple Python

Dead Simple Python

Jason C. McDonald

Publisher Resources

ISBN: 9781449397524Supplemental ContentErrata