Sobes.tech
Junior

What datasets are available in Python?

sobes.tech AI

Answer from AI

Main built-in data collections in Python:

  • Lists: Ordered, mutable sequences of elements. Elements can be of different types. Created using square brackets [].
  • Tuples: Ordered, immutable sequences of elements. Often used to store related data that should not change. Created using parentheses ().
  • Sets: Unordered collections of unique elements. Support set operations (union, intersection, difference). Created using curly braces {} or the set() function.
  • Dictionaries: Unordered collections of key-value pairs. Keys must be unique and immutable (e.g., strings, numbers, tuples). Values can be of any type. Created using curly braces {} with a colon between key and value.

Examples of usage:

# List
my_list = [1, "apple", 3.14]

# Tuple
my_tuple = (10, "banana", True)

# Set
my_set = {1, 2, 3, 2, 4} # Result: {1, 2, 3, 4}

# Dictionary
my_dict = {"name": "Alice", "age": 30}

Properties of data collections:

Data collection Ordered? Mutable? Duplicates allowed?
List Yes Yes Yes
Tuple Yes No Yes
Set No Yes No
Dictionary No Yes No (for keys)

Besides built-in collections, other data collections are available through the standard collections library, such as Counter, deque, defaultdict, and others. They provide specialized functionality.