Python – Sorting List Items
Python list items can be sorted using the sort() method in specified orders including reverse order.
Python list items can be sorted using the sort() method in specified orders including reverse order.
Python lists can be copied to a new list using the copy() method, list() function, or slice operator.
There are several ways to join, or concatenate, two or more lists in Python.
Python tuples are used to store multiple items in a single variable, and unlike a list, are unchangeable.
Python tuple items are indexed and can be accessed by referring to their index number.
When creating a Python tuple, items are normally assigned to it (“packing” a tuple). Extracting the items into variables is called “unpacking” the tuple.
Python tuples are unchangeable, meaning that you cannot change, add, or remove items once the tuple is created. But there are some workarounds.
Python tuple items can be looped through and accessed using a for loop or while loop.
Python sets are used to store multiple items in a single variable, and unlike a list, are unordered, unchangeable, and unindexed.
A specific item cannot be accessed in a set by referring to an index or a key. To access items, a for loop or the in keyword can be used.
Once a Python set is created, you cannot change its items, but you can add new items using the add() method and update() method.
Once a Python set is created, you cannot change its items, but you can remove items using the remove(), discard(), pop(), and clear() methods, and the del keyword.
Python set items can be accessed by looping through them using a for loop.
Python sets can be joined (combined) using the union(), update(), intersection(), difference(), and symmetric_difference() methods.
Items in a Python dictionary can be accessed by referring to its key name using several methods.
Items in a Python dictionary can be changed by referring to its key name or using the update() method.
Adding an item to a Python dictionary is done by using a new index key and assigning a value to it.
There are multiple ways to remove items from a Python dictionary: the pop(), popitem(), and clear() methods, as well as the del keyword.
Python dictionary items can be accessed by looping through them using a for loop.