Python Lists: Creating, Indexing and Slicing
A list is an ordered, changeable sequence that can hold anything. Indexing, slicing and slice assignment cover most of what you will ever do with one.
A complete core Python path: syntax, data types, operators, strings, control flow, collections, functions, exceptions, files, modules, the standard library, OOP, iterators, generators, decorators, internals, concurrency, regular expressions, testing, typing, performance, security, problem solving, projects, interview preparation and exams.
110 notes in 33 topics
A list is an ordered, changeable sequence that can hold anything. Indexing, slicing and slice assignment cover most of what you will ever do with one.
Most list methods change the list in place and return None. Knowing which ones return a value and which do not prevents the most common list bug.
Lists of lists model grids and tables, copying them needs care, and a handful of patterns cover most real list work.
A tuple is a list that cannot change. That single restriction makes it usable as a dictionary key, safe to share, and the natural way to return severa...
Unpacking pulls a sequence apart into names in one statement. It powers swapping, loops over pairs, multiple return values and the star syntax.
A set stores unique values with no order and answers membership questions almost instantly. That trade - lose order, gain speed and uniqueness - is th...
Four operations answer four everyday questions: what is in either, what is in both, what is only in the first, and what is in exactly one.
A dictionary maps keys to values and finds any value in roughly constant time. It is the most used container in Python and the structure most real dat...
setdefault, get with a default and the Counter class turn the most common dictionary jobs - counting, grouping and accumulating - into two or three li...
Real data arrives as dictionaries inside dictionaries inside lists. Reaching into it safely, walking it and flattening it are skills worth practising...
A comprehension builds a collection from an expression and a loop, in one line. It reads left to right in the same order as the loop it replaces.
The same syntax as a list comprehension, with a key and a value separated by a colon. It is the fastest way to build, filter, invert or reshape a mapp...