Understand Python Mappings and Dictionary types
collections.Mapping (read-only) or collections.MutableMapping (read-write). Common mapping classes include dict, collections.defaultdict, collections.OrderedDict, and collections.Counter.website·Indexed 29 days ago
https://stavis-dev.github.io/A personal collection of IT documentation and guides covering Python (data types, regex, unittest, binary search, and comprehensions), Linux command-line tips, and tool-specific manuals for UFW, ADB, GPG, WireGuard, and Docker. Also includes notes on Docusaurus and general soft skills.
collections.Mapping (read-only) or collections.MutableMapping (read-write). Common mapping classes include dict, collections.defaultdict, collections.OrderedDict, and collections.Counter.list in Python is a mutable data structure used to store a collection of objects. Unlike arrays in some other languages, Python lists can contain objects of different types. A list variable holds a reference to a container in memory, which in turn holds references to the actual data objects. Because lists are mutable, their size and contents can be changed after creation.str_one = 'Hello'
str_two = "Hello"
# Multi-line string
tunnel = """
interface Tunnel0
ip address 10.10.10.1 255.255.0.0
"""__getitem__() method and provides its length via the __len__() method. Common built-in sequence types include list, tuple, range, str, and bytes. Many sequences also optionally implement count(), index(), __contains__(), and __reversed__().-Syu. To check detailed information about a specific package version before updating, use -Qi.# Update system
sudo pacman -Syu
# Check package information/version
pacman -Qi visual-studio-code-binPython data types are categorized as either mutable or immutable.
id). Examples include numbers (int, float), strings, and tuples.id). Examples include lists, dictionaries, and sets.This distinction is critical when passing objects to functions; to prevent a function from modifying an original list, a copy of the list should be passed instead.
# Immutable example: integers
int_var = 5
print(f"first id: {id(int_var)}")
int_var += 10
print(f"second id: {id(int_var)}") # The id changes because a new object is created
# Mutable example: lists
list_var = [10, 20, 30]
print(f"first id: {id(list_var)}")
list_var += [40]
print(f"second id: {id(list_var)}") # The id remains the samere module to work with regular expressions, allowing developers to match strings or find specific patterns using specialized syntax. The module includes functions for searching, matching, replacing, and splitting strings based on regex patterns.Python dictionaries are implemented as sparse arrays of 'buckets'. Each bucket contains a reference to the key and the value.
hash(key) to get a hash value. The lower bits of this value are used as an offset to find the bucket.search_key == found_key to ensure the correct element is retrieved. If the bucket is empty, a KeyError is raised.Example: Person A: "Smoking is harmful to health; people should not smoke." Person B: "But you were smoking a few minutes ago. Therefore, smoking is allowed."
__iter__ and __next__ methods, making them both iterables and iterators.