Need Assistance?

support@tutorialshub.in

Collections and Strings

Lists

ADVERTISEMENT
Python Free Lesson
5 min read
ADVERTISEMENT

Tuples represent fixed sequences

Tuples are immutable sequences and are useful when a group of values should not be changed through normal sequence operations. They are also commonly used for returning multiple values from a function.

Sets represent uniqueness

A set stores unique hashable values. It is excellent for membership checks, duplicate removal and mathematical operations such as union, intersection and difference.

Choose based on the operation

Do not use a set when application order is the primary meaning of the data. Do not use a tuple merely because it looks shorter than a list; choose it when immutability or tuple semantics are useful.

Practice: compare two lists of course IDs and find common courses, courses unique to each list and the combined unique course set.

ADVERTISEMENT