Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Python 3 Object-Oriented Programming - Second Edition

You're reading from  Python 3 Object-Oriented Programming - Second Edition

Product type Book
Published in Aug 2015
Publisher Packt
ISBN-13 9781784398781
Pages 460 pages
Edition 1st Edition
Languages
Author (1):
Dusty Phillips Dusty Phillips
Profile icon Dusty Phillips

Table of Contents (21) Chapters

Python 3 Object-oriented Programming Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Introduction to the second edition
Preface
1. Object-oriented Design 2. Objects in Python 3. When Objects Are Alike 4. Expecting the Unexpected 5. When to Use Object-oriented Programming 6. Python Data Structures 7. Python Object-oriented Shortcuts 8. Strings and Serialization 9. The Iterator Pattern 10. Python Design Patterns I 11. Python Design Patterns II 12. Testing Object-oriented Programs 13. Concurrency Index

Sets


Lists are extremely versatile tools that suit most container object applications. But they are not useful when we want to ensure objects in the list are unique. For example, a song library may contain many songs by the same artist. If we want to sort through the library and create a list of all the artists, we would have to check the list to see if we've added the artist already, before we add them again.

This is where sets come in. Sets come from mathematics, where they represent an unordered group of (usually) unique numbers. We can add a number to a set five times, but it will show up in the set only once.

In Python, sets can hold any hashable object, not just numbers. Hashable objects are the same objects that can be used as keys in dictionaries; so again, lists and dictionaries are out. Like mathematical sets, they can store only one copy of each object. So if we're trying to create a list of song artists, we can create a set of string names and simply add them to the set. This example...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}