Skip to content

Core Data Structures in Python

Python provides several built-in collection types that are used to store, organize, and manipulate data efficiently.
These data structures are flexible and map closely to collections in C# and JavaScript.

nums = [1, 2, 3]

A list is:

  • Ordered collection
  • Mutable (can be changed)
  • Can store duplicate values
  • Can store mixed data types
  • Maintains insertion order
  • Elements can be added, removed, or modified
  • Index-based access
nums.append(4)
nums[0] = 10
List<int> nums = new List<int> { 1, 2, 3 };
const nums = [1, 2, 3];

point = (4, 5)

A tuple is:

  • Ordered collection
  • Immutable (cannot be changed)
  • Typically used for fixed collections of values
  • Faster than lists
  • Often used for coordinates, pairs, and return values
  • Safer when data should not change
x, y = point # tuple unpacking
(int x, int y) point = (4, 5);

JavaScript does not have tuples natively, but arrays are used:

const point = [4, 5];

user = {"name": "Ada"}

A dictionary:

  • Stores key–value pairs
  • Keys must be unique
  • Values can be of any type
  • Mutable
  • Fast lookups by key
  • Insertion order preserved (Python 3.7+)
user["age"] = 30
Dictionary<string, string> user = new Dictionary<string, string>
{
{ "name", "Ada" }
};
const user = { name: "Ada" };

unique = {1, 2, 2, 3}

A set is:

  • Unordered collection
  • Stores unique values only
  • Automatically removes duplicates

Result:

{1, 2, 3}
  • No indexing
  • Extremely fast membership checks
  • Useful for removing duplicates and set operations
2 in unique # True
HashSet<int> unique = new HashSet<int> { 1, 2, 2, 3 };
const unique = new Set([1, 2, 2, 3]);

Python TypeOrderedMutableAllows DuplicatesC# EquivalentJavaScript Equivalent
listList<T>Array
tuple(T1, T2)Array
dict❌ (keys)Dictionary<TKey, TValue>Object
setHashSet<T>Set

  • List → Ordered, changeable collections
  • Tuple → Fixed, read-only groupings
  • Dictionary → Key-value relationships
  • Set → Unique values and fast membership checks

  • Python’s core data structures are powerful and flexible
  • They closely map to familiar C# and JavaScript collections
  • Choosing the right structure improves performance and readability
  • Understanding mutability and ordering is critical