Problem Statement
When should you choose list, tuple, set, or dict? Explain with trade-offs.
Explanation
Use a list for ordered, indexable collections that change over time; appends are fast and you keep duplicates. Choose a tuple for fixed records that must not change; immutability improves safety and allows use as dictionary keys when elements are hashable.
Pick a set when you need uniqueness and fast membership tests; set operations like union and intersection are expressive and efficient. Use a dict when you must map keys to values with O(1) average lookup; it is the most common structure for labelled data and configuration.
Think about mutability, need for keys, and performance. For example, membership tests in a set or dict are O(1) average, while in a list they are O(n).
Code Solution
SolutionRead Only
users=['a','b','b']
unique=set(users)
points={('lat','lon'): (30.1,78.0)}