SoftPython
dev
  • Home
    • News
    • Intended audience
    • Contents
      • A - Foundations
      • B - Data analysis
    • Authors
    • License
    • Acknowledgments
  • Overview
    • Chapters
    • Why Python?
    • Approach and goals
    • Doesn’t work, what should I do?
      • How to ask questions
    • Installation and tools
    • Let’s start !
  • References
    • Allen Downey - Think Python
    • W3Resources website
    • Software Carpentry
    • Edabit
      • Edabit - Basics
      • Edabit - Strings
      • Edabit - Lists
      • Edabit - Dictionaries
      • Edabit - Matrices
    • LeetCode
      • LeetCode - Strings
      • LeetCode - Lists
      • LeetCode - Sets and Dictionaries
    • LeetCode - Matrices
    • HackerRank
    • Geeks for Geeks
    • Dive into Python 3
    • Introduction to Scientific Programming with Python
  • Installation
    • Installing Python
      • Windows installation
      • Mac installation
      • Linux installation
    • Installing packages
    • Jupyter Notebook
      • Run Jupyter notebook
      • Saving Jupyter notebooks
      • Turning off Jupyter server
      • Navigating notebooks
      • Installing Jupyter notebook - all operating systems
    • Projects with virtual environments
      • Creating virtual environments
      • Activate a virtual environment
      • Executing environments inside Jupyter
        • With Anaconda
        • Without Anaconda
    • Further readings
  • A - Foundations
    • Tools and scripts
      • Download exercises zip
      • Python interpreter
        • Let’s open system console
        • Listing files and folders
        • Let’s launch the Python interpreter
        • Exiting the interpreter
      • Modules
        • Simple text editor
        • IDE
      • Jupyter
        • Printing an expression
        • Exercise - Castles in the air
      • Visualizing the execution with Python Tutor
        • Debugging code in Jupyter
        • Exercise - tavern
      • Python Architecture
        • Python is a high level language
        • Performance
    • Basics
      • Download exercises zip
      • Jupyter
      • Objects
      • Variables
        • Detect the type of a variable
        • Reassign a variable
        • Reusing a variable
        • Assignments - questions
        • Exercise - exchange
        • Exercise - cycling
        • Changing type during execution
        • Multiple commands on the same line
        • Multiple initializations
        • Exercise - exchange like a ninja
        • Names of variables
        • Names of variables - questions
      • Numerical types
      • Integer numbers
        • Exercise - deadline 1
        • Modulo operator
        • Exercise - deadline 2
        • min and max
        • Exercise - transportation
        • Exercise - armchairs
      • Booleans
        • Boolean operators
        • Booleans - Questions with costants
        • Booleans - Questions with variables
        • Booleans - De Morgan
        • Booleans - Conversion
        • Booleans - Questions - what is a boolean?
        • Booleans - Evaluation order
        • Booleans - evaluation errors
        • Comparison operators
        • Booleans - References
      • Real numbers
        • Scientifical notation
        • Too big or too small numbers
        • Exercise - circle
        • Exercise - fractioning
        • Exercise - summation
        • Reals - conversion
        • Exercise - Invigorate
        • Exercise - roundminder
        • Reals - equality
        • Exercise - quadratic
        • Exercise - trendy
      • Decimal numbers
      • Challenges
        • Challenge - which booleans 1?
        • Challenge - which booleans 2?
        • Challenge - Triangle area
        • Challenge - square area
        • Challange - area from input
        • Challenge - trapezoid
        • Challenge - first n numbers
        • challenge - hypotenuse
        • Challenge - which integers 1?
        • Challenge - which integers 2?
        • Challenge - which integers 3?
        • Challenge - airport
        • Challenge - Holiday trip
      • References
    • Strings 1: Introduction
      • Download exercises zip
      • What to do
      • Creating strings
      • Printing - the cells
      • The empty string
      • Printing many strings
      • Length of a string
      • Printing - escape sequences
        • Esempio - line feed
        • Example - tabulation
      • Encodings
        • ASCII characters
        • Unicode characters
      • Strings are immutable
        • Reassign variables
        • Reassign a variable to itself
      • Strings and numbers
      • Conversions - from string to number
      • Conversions - from number to string
      • Formatting strings
        • Formatting with %
        • Exercise - supercars
      • References
      • Continue
    • Strings 2: Operators
      • Download exercises zip
      • What to do
      • Reading characters
        • Exercise - alternate
        • Negative indexes
      • Substitute characters
      • Slices
        • Exercise - garalampog
        • Exercise - ifEweEfav lkSD lkWe
        • Slices - limits
        • Slice - Omitting limits
        • Exercise - ysterymyster
        • Slice - negative limits
        • Exercise - javarnanda
        • Slice - modifying
        • Exercise - the run
      • in operator
        • Exercise - contained 1
        • Exercise - contained 2
      • Comparisons
        • Equality operators
        • Exercise - statist
        • Comparing characters
        • Comparing different lengths
        • Exercise - Character intervals
      • Replication operator
        • Exercise - za za za
      • Continue
    • Strings 3: Methods
      • Download exercises zip
      • What to do
      • Example - upper
      • Exercise - walking
      • lower method
        • Exercise - lowermid
      • capitalize method
        • Exercise - Your Excellence
      • strip method
        • Specificying character to strip
      • lstrip method
      • rstrip method
        • Exercise - hatespace
        • Exercise - Bad to the bone
      • replace method
        • Exercise - substitute
      • startswith method
        • Exercise - by Jove
      • endswith method
        • Exercise - Snobbonis
      • count method
        • Exercise - astro money
      • find method
        • Exercise - bananas
      • rfind method
      • isalpha method
      • isdigit method
      • isupper and islower methods
      • Other exercises
      • Continue
    • Lists 1: Introduction
      • Download exercises zip
      • What to do
      • Creating lists
        • Empty list
        • Exercise - create lists 1
        • Exercise - create lists 2
        • Exercise - create lists 3
        • Exercise - create lists 4
      • Convert sequences into lists
        • Exercise - gulp
        • Exercise - garaga
      • References
      • Continue
    • Lists 2: Operators
      • Download exercises zip
      • What to do
      • Length of a list
      • Reading an element
      • Writing an element
      • Mutating shared lists
      • Slices
        • Slice - limits
        • Slices - omitting limits
        • Slices - negative limits
        • Slices - modifying
      • List of strings
        • Exercise - province codes
        • Exercise - games
      • List of lists
        • Exercise - couples
        • Exercise - nonunif
      • in operator
        • not in
        • Exercise - vegetables
      • List concatenation with +
        • Exercise - concatenation
      • min and max
      • sum
        • Exercise - balance
      • Multiplying lists
      • Equality
      • Continue
    • Lists 3: Methods
      • Download exercises zip
      • What to do
      • append method
        • Exercise - augmenting a list 1
      • extend method
        • Extending with sequences
        • Exercise: augmenting a list 2
        • Exercise - zslice
        • Exercise - Zebarerun
      • join - build strings from lists
        • Exercise - dub dab dib dob
        • Exercise - ghirigori
        • Exercise - welldone
      • insert method
        • Exercise - insertando
        • Exercise - barzoletta
        • Exercise - insappend
      • remove method
        • Exercise - nob
      • pop method
        • Exercise - popcorn
        • Exercise - zonzo
      • reverse method
        • Exercise - good manners
      • Exercise - precious things
      • Exercise - powers
      • sort method
        • Custom sorting
        • Exercise - manylines
        • Exercise - numlist
      • index method
      • count method
      • Continue
    • Tuples
      • Download exercise zip
      • What to do
      • Creating tuples
        • Empty tuple
        • Tuples without brackets
        • Heterogenous elements
        • Creating tuples from sequences
        • Creating sequences from tuples
      • Operators
        • len
        • Reading an element
        • Exercise - animals
        • Slices
        • Concatenation
        • Membership
        • Multiplication
        • Exercise - welcome
      • Write an element
        • Exercise - badmod
        • Exercise - abde
        • Exercise - charismatic
        • Exercise - sorting
      • Methods
        • index method
        • count method
        • Exercise - fruits
      • Exercises with functions
        • Exercise - touples
        • Exercise - joined
      • Verify comprehension
        • doubles
        • nasty
      • References
    • Sets
      • Download exercises zip
      • What to do
      • Creating a set
        • Converting sequences to sets
        • Mutable elements and hashes
        • Empty set
        • Exercise - dedup
        • Frozenset
      • Operators
        • len
        • Exercise - distincts
        • Union
        • Exercise - everythingbut 1
        • Intersection
        • Difference
        • Symmetric difference
        • Membership
      • Equality
      • Methods like operators
        • union
        • update
        • Exercise - everythingbut 2
      • Other methods
        • add method
        • remove method
        • Exercise - bababiba
        • discard method
        • Exercise - trash
        • issubset method
        • issuperset method
        • isdisjoint method
      • Exercise - matrioska
      • Exercise with functions
        • Exercise - syllabs
        • Exercise - distinguish
      • Verifify comprehension
        • Exercise - intersectron
      • References
    • Dictionaries 1: Introduction
      • Download exercises zip
      • What to do
      • Creating a dictionary
        • The keys
        • The values
        • Empty dictionary
        • Keys and heterogenous values
      • Dictionary from a sequence of couples
      • Dictionary from keyword arguments
      • Copying a dictionary
        • Shallow copy
        • Deep copy
      • Continue
    • Dictionaries 2: Operators
      • Download exercise zip
      • What to do
      • len
      • Reading a value
        • Fast disorder
        • Exercise - z7
      • Writing in the dictionary
        • Writing - adding key/value
        • Writing - reassociate a key
        • Exercise - workshop
        • Writing - deleting
        • Exercise - desktop
        • Exercise - garden
        • Exercise - translations
      • Membership with in
        • not in
      • Dictionaries of sequences
      • Exercise - loans
      • Equality
        • Equality and order
        • Equality and copies
      • Exercise - ZOOM DOOM
      • Continue
    • Dictionaries 3: Methods
      • Download exercise zip
      • What to do
      • keys method
        • Exercise - messy keys
        • Exercise - sorted keys
        • Exercise - keyring
      • values method
      • Exercise - one by one
      • Exercise - bag
        • Exercise - common values
        • Exercise - small big
      • items method
        • Exercise - union without update
      • update method
      • Exercise - axby
      • Classes - OrderedDict
        • Exercise - phonebook
      • Exercise - OrderedDict copy
      • Classes - Counter
      • Exercise - saddened
      • Continue
    • Control flow 1: if
      • Download exercises zip
      • What to do
      • The basic command if else
      • else is optional
      • Exercise - no fuel
      • The command if - elif - else
        • Questions
      • Questions - Are they equivalent?
        • Are they equivalent? - strawberries
        • Are they equivalent? - max
        • Are they equivalent? - min
        • Are they equivalent? - big small
        • Are they equivalent? - Cippirillo
        • Exercise - farm
        • Exercise - accents
        • Exercise - Arcana
      • Nested ifs
        • Exercise - abscissae and ordinates 1
        • Esercise - abscissae and ordinates 2
        • Exercise - bus
        • Exercise - chronometer
      • Questions - Are they equivalent?
        • Are they equivalent? - inside outside 1
        • Are they equivalent? - stars planets
        • Are they equivalent? - green red
        • Are they equivalent? - circles squares
        • Are they equivalent? - inside outside 2
        • Are they equivalent? - Ciabanga
        • Exercise - The maximum
      • Ternary operator
        • Questions ternary ifs
        • Exercise - shoes
        • Exercise - the little train
      • References
    • Control flow 2: for
      • Download exercises zip
      • What to do
      • Iteration by element
        • Names of variables in for
        • Iterating strings
        • Iterating tuples
        • Questions - iteration
        • Exercise - magic carpet
        • Esercise - evensum
        • Exercise - birbantello
        • Exercise - articulate
        • Exercise - gala
        • Exercise - balance
      • Counting with range
        • Questions - range
        • Exercise - printdoubles
        • Exercise - multiples or not
        • Exercise - ab interval
      • Iterating by index
        • Exercise - kitchen
        • Exercise - neon
        • Exercise - emotions
        • Exercise - organetto
        • Exercise - sghiribizzo
        • Exercise - dna
        • Exercise - sportello
        • Exercise - farm
        • Exercise - pokemon
      • Modifying during iteration
        • Exercise - duplicate
        • Exercise - hammers
        • Exercise - Orangutan
        • Exercise - basket
      • Iterating a set
        • Questions - sets
      • Iterating a dictionary
        • Dictionary iteration - questions
        • Questions - Are they equivalent?
        • Are they equivalent ? postin
        • Are they equivalent ? cortel
        • Are they equivalent ? - gel
        • Are they equivalent ? - giri
        • Are they equivalent - Found
        • Exercise - color of hearts
        • Exercise - jewels
        • Exercise - powers
        • Exercise - flowers
        • Exercise - art
        • Exercise - stationery stores
        • Exercise - legumes
        • Exercise - sports
        • Modifying a dictionary during iteration
        • Exercise - zazb
      • Nested for
        • Questions - nested for
        • Exercise - casting
        • Exercise - cover the plane
        • Exercise - triangular
        • Exercise - port
        • Exercise - polygons
        • Exercise - bon jour
      • break and continue commands
        • Terminate with break
        • Jumping with continue
        • Combining break and continue
        • Questions - break and continue
        • Exercise - autonomous walking
        • Exercise - breaking bad
        • Exercise - breaking point
        • Exercise - breakdance
    • Control flow 3: while
      • Download exercises zip
      • What to do
      • Introduction
        • Terminating while
        • Non terminating while
        • Questions
        • Esercises - introduction
        • Exercise - printeven
        • Exercise - average
      • break and continue commands
        • Terminate with a break
        • Jumping with continue
        • Questions about break and continue
        • Exercise - findchar
      • Questions - Are they equivalent?
        • Are they equivalent? - BORG
        • Are they equivalent? - until 3
        • Are they equivalent? - by chance
        • Are they equivalent? - until six
        • Are they equivalent? - countdown 1
        • Are they equivalent? - countdown 2
        • Are they equivalent? - sorcery
        • Are they equivalent? - ping pong
        • Are they equivalent? - zanna
        • Are they equivalent? - pasticcio
      • Exercises - counters
        • Exercise - don’t break 1
        • Exercise - don’t break 2
        • Exercise - Give me a break
        • Exercise - paperboard
        • Exercise - until ten
        • Exercise - cccc
        • Exercise - converge
        • Exercise - wow
        • Exercise - Wild West
      • Modifying sequences
        • Stack - Drawing from a card deck
        • Stack - Drawing until condition
        • Exercise - Don’t break my heart
        • Questions - what happens?
        • Questions - are they equivalent?
        • Are they equivalent? - train
        • Are they equivalent? - append nx
      • Exercises - stack
        • Exercise - break sum
        • Exercise - travelbook
        • Exercise - BANG !
        • Exercise - Growing or degrowing?
      • References
    • Sequences and comprehensions
      • Download exercises zip
      • What to do
      • Iterables - lists
      • iterables - range
      • Materializing a sequence
        • Questions - range
      • reversed
        • Iterating with next
        • Exercise - sconcerto
        • Materializing an iterator
      • sorted
        • Exercise - reversort
      • zip
        • Exercise - ladder
      • List comprehensions
        • List comprehensions on strings
      • Questions - List comprehensions
      • Exercises - list comprehension
        • Exercise - power
        • Exercise - root
        • Exercise - first chars
        • Exercise - don’t worry
        • Exercise - greater than 3
        • Exercise - even
        • Exercise - both ends
        • Exercise - dashes
        • Exercise - lollosa
        • Exercise - dog cat
        • Exercise - smurfs
        • Exercise - precious metals
      • Filtered list comprehensions
      • Questions - filtered list comprehensions
      • Exercises - filtered list comprehensions
        • Exercise - savannah
        • Exercise - puZZled
      • References
    • Matrices: list of lists
      • Download exercises zip
      • Introduction
      • What to do
        • Overview
      • Exercises
        • Matrix dimensions
      • Extracting rows and columns
        • How to extract a row
        • Extracting row pointers
        • extrowf
        • Extract row with range
        • Extract row with a slice
        • Extract row with list comprehension
        • Extract column with a for
        • Extract column with a list comprehension
      • Creating new matrices
        • empty matrix
        • empty_matrix the elegant way
        • deep_clone
      • Modifying matrices
        • fillc
        • fillx
        • fillz
        • stitch_down
        • stitch_up
        • stitch_right
        • threshold
        • swap_rows
        • swap_cols
      • Other exercises
        • diag
        • anti_diag
        • is_utriang
        • stitch_left_mod
        • transpose_1
        • transpose_2
        • lab
        • dump
        • matrix multiplication
        • check_nqueen
    • Matrices: Numpy
      • Download exercises zip
      • Introduction
        • What to do
      • np.array
      • NaNs and infinities
        • NaNs
        • Detecting NaN
        • Sequences with NaNs
        • Exercise NaN: two vars
        • Operations on NaNs
        • NaN and Numpy
        • Where are the NaNs ?
        • Infinities
        • Positive infinity np.inf
        • Negative infinity
        • Combining infinities and NaNs
        • Negative zero
        • Exercise: detect proper numbers
        • Exercise: guess expressions
      • Verify comprehension
        • odd
        • doublealt
        • frame
        • chessboard
        • altsum
        • avg_rows
        • avg_half
        • matxarr
        • quadrants
        • matrot
      • References
        • Other Numpy exercises
    • Matrices: Numpy images
      • Download exercises zip
        • What to do
      • Introduction
        • Monochrome
      • Focus
        • Exercise - Head focus
      • hstack and vstack
        • Exercise - Passport
      • flip
        • Exercise - Too many
        • Exercise - The nose from above
      • Writing arrays
      • Writing into images
        • Exercise - Stripes
      • In a dark integer night
        • The Integer Shining
        • Exercise - Be bright
      • RGB - Get colorful
      • Exercise - Focus - top left
      • Exercise - Focus - bottom - left
      • Exercise - Focus - bottom - right
      • Exercise - Focus - top - right
      • Exercise - Look the other way
      • Exercise - Upside down world
      • Exercise - Shrinking Walls - X
      • Exercise - Shrinking Walls - Y
      • Exercise - Shrinking World
      • Exercise - Pixellate
      • Exercise - Feeling Red
      • Exercise - Feeling Green
      • Exercise - Feeling Blue
      • Exercise - No Red
      • Exercise - No Green
      • Exercise - No Blue
      • Exercise - Feeling Gray again
      • Exercise - Beyond the limit
      • Exercise - Gimme light
      • Exercise - When the darkness comes - with a warning
      • Exercise - When the darkness comes - without a warning
      • Exercise - Fade to black
      • Exercise - vertical fade
    • Errors and testing
      • Download exercises zip
      • Introduction
        • What to do
      • Unforeseen situations
        • make_problematic_pie
      • Check with the return
      • Exceptions
        • Manage exceptions
        • Particular exceptions
      • assert
        • When to use assert?
      • Testing
        • Where Is Your Software?
      • Testing with asserts
        • Exercise structure
        • even_numbers example
        • Error kinds
    • Commandments
      • I COMMANDMENT
      • II COMMANDMENT
      • III COMMANDMENT
      • IV COMMANDMENT
      • V COMMANDMENT
      • VI COMMANDMENT
      • VII COMMANDMENT
      • VIII COMMANDMENT
      • IX COMMANDMENT
      • X COMMANDMENT
  • B - Data analysis
    • Data formats (CSV, JSON)
      • Download exercises zip
      • Introduction
        • What to do
      • 1. line files
        • open command
        • The encoding
        • with block
        • people-complex line file:
        • Exercise - line file immersione-in-python-toc
      • 2. CSV files
        • Why parsing a CSV ?
        • Reading a CSV
        • Writing a CSV
        • Reading and writing a CSV
        • CSV Botteghe storiche
        • Problem: wrong characters ??
        • Botteghe storiche in Python
        • Botteghe storiche - rank_categories
        • Botteghe storiche - enrich
      • 3. JSON files
        • JSONL
    • Graph formats
      • Download exercises zip
      • Introduction
        • What to do
        • Required libraries
        • Graph definition
        • Edge weights
      • Matrices
        • Visualization examples
        • Saving a graph to an image file
        • Saving a graph to an dot file
        • Minimal graph
        • Graph with two nodes example
        • Distance matrix
        • Boolean matrix example
        • Matrix exercises
        • Exercise - line
        • Exercise - cross
        • union
        • Exercise - union
        • Subgraph
        • Exercise - is_subgraph
        • Exercise - remove_node
        • Exercise - utriang
        • Edge difference
        • Exercise - ediff
        • Exercise - pyramid
      • Adjacency lists
        • Exercise - mat_to_adj
        • Exercise - mat_ids_to_adj
        • Exercise - adj_to_mat
        • Exercise - table_to_adj
      • Networkx
        • Converting networkx graphs
        • Exercise - mat_to_nx
      • Simple statistics
        • Outdegrees and indegrees
        • Exercise - outdegree_adj
        • Exercise - outdegree_mat
        • Exercise - outdegree_avg
        • Exercise - indegree_adj
        • Exercise - indegree_mat
        • Exercise - indegree_avg
        • Was it worth it?
        • Exercise - min_outdeg
        • networkx Indegrees and outdegrees
    • Binary relations
      • Download exercises zip
      • What to do
      • Reflexive relations
        • Exercise - is_reflexive_mat
        • Exercise - is_reflexive_adj
      • Symmetric relations
        • Exercise - is_symmetric_mat
        • Exercise - is_symmetric_adj
      • Surjective relations
        • Exercise - surjective
      • Further resources
    • Visualization
      • Download exercises zip
      • Introduction
        • What to do
      • First example
        • Plot style
        • x power 2 exercise
        • Axis limits
        • Axis size
        • Changing tick labels
      • Introducting numpy
        • Example without numpy
        • Example with numpy
        • y = sin(x) + 3 exercise
        • Showing degrees per node
        • indegree per node
      • Bar plots
        • indegree per node bar plot
        • indegree per node sorted alphabetically
        • indegree per node sorted
        • out degrees per node sorted
        • degrees per node
      • Frequency histogram
      • Showing plots side by side
        • Graph models
      • Other plots
        • Pie chart
      • References
    • Visualization - The AlgoRythm Opera Challenge
      • Download exercises zip
      • The variables
      • 1. plot_sheet
      • 2. plot_pentagram
      • 3. plot_notes
      • Final result 1
      • Final result 2
    • Pandas analytics
      • Download exercises zip
      • 1. Introduction
        • What to do
        • Check installation
      • 2. Data analysis of Astro Pi
        • 2.1 Exercise: meteo info
      • 3. Indexing, filtering, ordering
        • 3.1 Exercise: Meteo stats
      • 4. MatPlotLib review
        • Matplotlib plots from pandas datastructures
      • 5. Calculating new columns
        • 5.1 Exercise: Meteo Fahrenheit temperature
        • 5.2 Exercise: Pressure vs Temperature
      • 6. Object values
        • Filter by textual values
        • Extracting strings
      • 7. Transforming
      • 8. Grouping
      • 9. Exercise: meteo average temperatures
        • 9.1 meteo plot
        • 9.2 meteo pressure and raining
        • 9.3 meteo average temperature
      • 10. Merging tables
        • Exercise 10.1 better merge
      • Continue
      • References
    • Pandas analytics - EURES Job Offers
      • Download exercises and solution
        • What to do
      • offerte dataset
      • rename columns
      • 1. Rename countries
        • 1.1 countries_to_list
        • 1.2 Filling column Workplace Country
      • 2. Work dates
        • 2.1 from_to function
        • 2.2. From To columns
      • 3. Required languages
        • 3.1 function reqlan
        • 3.2 Languages column
    • Pandas analytics challenge - Italian poets
      • Download exercises
        • What to do
      • Load the dataset
      • Tell me more
      • Getting in shape
      • 10 rows
      • Born in Verona
      • How many people in Verona
      • Python is everywhere
      • Verona after 1500
      • First Antonio
      • Some Antonio
      • Cesares during 1800
      • Sorting
      • Where poets are born
      • Duplicated poets
  • Index
SoftPython
  • Home
    • News
    • Intended audience
    • Contents
      • A - Foundations
      • B - Data analysis
    • Authors
    • License
    • Acknowledgments
  • Overview
    • Chapters
    • Why Python?
    • Approach and goals
    • Doesn’t work, what should I do?
      • How to ask questions
    • Installation and tools
    • Let’s start !
  • References
    • Allen Downey - Think Python
    • W3Resources website
    • Software Carpentry
    • Edabit
      • Edabit - Basics
      • Edabit - Strings
      • Edabit - Lists
      • Edabit - Dictionaries
      • Edabit - Matrices
    • LeetCode
      • LeetCode - Strings
      • LeetCode - Lists
      • LeetCode - Sets and Dictionaries
    • LeetCode - Matrices
    • HackerRank
    • Geeks for Geeks
    • Dive into Python 3
    • Introduction to Scientific Programming with Python
  • Installation
    • Installing Python
      • Windows installation
      • Mac installation
      • Linux installation
    • Installing packages
    • Jupyter Notebook
      • Run Jupyter notebook
      • Saving Jupyter notebooks
      • Turning off Jupyter server
      • Navigating notebooks
      • Installing Jupyter notebook - all operating systems
    • Projects with virtual environments
      • Creating virtual environments
      • Activate a virtual environment
      • Executing environments inside Jupyter
        • With Anaconda
        • Without Anaconda
    • Further readings
  • A - Foundations
    • Tools and scripts
      • Download exercises zip
      • Python interpreter
        • Let’s open system console
        • Listing files and folders
        • Let’s launch the Python interpreter
        • Exiting the interpreter
      • Modules
        • Simple text editor
        • IDE
      • Jupyter
        • Printing an expression
        • Exercise - Castles in the air
      • Visualizing the execution with Python Tutor
        • Debugging code in Jupyter
          • Python Tutor : Limitation 1
          • Python Tutor : Limitation 2
        • Exercise - tavern
      • Python Architecture
        • Python is a high level language
        • Performance
    • Basics
      • Download exercises zip
      • Jupyter
      • Objects
      • Variables
        • Detect the type of a variable
        • Reassign a variable
        • Reusing a variable
        • Assignments - questions
        • Exercise - exchange
        • Exercise - cycling
        • Changing type during execution
        • Multiple commands on the same line
        • Multiple initializations
        • Exercise - exchange like a ninja
        • Names of variables
        • Names of variables - questions
      • Numerical types
      • Integer numbers
        • Exercise - deadline 1
        • Modulo operator
        • Exercise - deadline 2
        • min and max
        • Exercise - transportation
        • Exercise - armchairs
      • Booleans
        • Boolean operators
        • Booleans - Questions with costants
        • Booleans - Questions with variables
        • Booleans - De Morgan
        • Booleans - Conversion
        • Booleans - Questions - what is a boolean?
        • Booleans - Evaluation order
        • Booleans - evaluation errors
        • Comparison operators
        • Booleans - References
      • Real numbers
        • Scientifical notation
        • Too big or too small numbers
        • Exercise - circle
        • Exercise - fractioning
        • Exercise - summation
        • Reals - conversion
        • Exercise - Invigorate
        • Exercise - roundminder
        • Reals - equality
        • Exercise - quadratic
        • Exercise - trendy
      • Decimal numbers
      • Challenges
        • Challenge - which booleans 1?
        • Challenge - which booleans 2?
        • Challenge - Triangle area
        • Challenge - square area
        • Challange - area from input
        • Challenge - trapezoid
        • Challenge - first n numbers
        • challenge - hypotenuse
        • Challenge - which integers 1?
        • Challenge - which integers 2?
        • Challenge - which integers 3?
        • Challenge - airport
        • Challenge - Holiday trip
      • References
    • Strings 1: Introduction
      • Download exercises zip
      • What to do
      • Creating strings
      • Printing - the cells
      • The empty string
      • Printing many strings
      • Length of a string
      • Printing - escape sequences
        • Esempio - line feed
        • Example - tabulation
      • Encodings
        • ASCII characters
        • Unicode characters
      • Strings are immutable
        • Reassign variables
        • Reassign a variable to itself
      • Strings and numbers
      • Conversions - from string to number
      • Conversions - from number to string
      • Formatting strings
        • Formatting with %
        • Exercise - supercars
      • References
      • Continue
    • Strings 2: Operators
      • Download exercises zip
      • What to do
      • Reading characters
        • Exercise - alternate
        • Negative indexes
      • Substitute characters
      • Slices
        • Exercise - garalampog
        • Exercise - ifEweEfav lkSD lkWe
        • Slices - limits
        • Slice - Omitting limits
        • Exercise - ysterymyster
        • Slice - negative limits
        • Exercise - javarnanda
        • Slice - modifying
        • Exercise - the run
      • in operator
        • Exercise - contained 1
        • Exercise - contained 2
      • Comparisons
        • Equality operators
        • Exercise - statist
        • Comparing characters
        • Comparing different lengths
        • Exercise - Character intervals
      • Replication operator
        • Exercise - za za za
      • Continue
    • Strings 3: Methods
      • Download exercises zip
      • What to do
      • Example - upper
      • Exercise - walking
      • lower method
        • Exercise - lowermid
      • capitalize method
        • Exercise - Your Excellence
      • strip method
        • Specificying character to strip
      • lstrip method
      • rstrip method
        • Exercise - hatespace
        • Exercise - Bad to the bone
      • replace method
        • Exercise - substitute
      • startswith method
        • Exercise - by Jove
      • endswith method
        • Exercise - Snobbonis
      • count method
        • Exercise - astro money
      • find method
        • Exercise - bananas
      • rfind method
      • isalpha method
      • isdigit method
      • isupper and islower methods
      • Other exercises
      • Continue
    • Lists 1: Introduction
      • Download exercises zip
      • What to do
      • Creating lists
        • Empty list
        • Exercise - create lists 1
        • Exercise - create lists 2
        • Exercise - create lists 3
        • Exercise - create lists 4
      • Convert sequences into lists
        • Exercise - gulp
        • Exercise - garaga
      • References
      • Continue
    • Lists 2: Operators
      • Download exercises zip
      • What to do
      • Length of a list
      • Reading an element
      • Writing an element
      • Mutating shared lists
      • Slices
        • Slice - limits
        • Slices - omitting limits
        • Slices - negative limits
        • Slices - modifying
      • List of strings
        • Exercise - province codes
        • Exercise - games
      • List of lists
        • Exercise - couples
        • Exercise - nonunif
      • in operator
        • not in
        • Exercise - vegetables
      • List concatenation with +
        • Exercise - concatenation
      • min and max
      • sum
        • Exercise - balance
      • Multiplying lists
      • Equality
      • Continue
    • Lists 3: Methods
      • Download exercises zip
      • What to do
      • append method
        • Exercise - augmenting a list 1
      • extend method
        • Extending with sequences
        • Exercise: augmenting a list 2
        • Exercise - zslice
        • Exercise - Zebarerun
      • join - build strings from lists
        • Exercise - dub dab dib dob
        • Exercise - ghirigori
        • Exercise - welldone
      • insert method
        • Exercise - insertando
        • Exercise - barzoletta
        • Exercise - insappend
      • remove method
        • Exercise - nob
      • pop method
        • Exercise - popcorn
        • Exercise - zonzo
      • reverse method
        • Exercise - good manners
      • Exercise - precious things
      • Exercise - powers
      • sort method
        • Custom sorting
        • Exercise - manylines
        • Exercise - numlist
      • index method
      • count method
      • Continue
    • Tuples
      • Download exercise zip
      • What to do
      • Creating tuples
        • Empty tuple
        • Tuples without brackets
        • Heterogenous elements
        • Creating tuples from sequences
        • Creating sequences from tuples
      • Operators
        • len
        • Reading an element
        • Exercise - animals
        • Slices
        • Concatenation
        • Membership
          • not in
        • Multiplication
        • Exercise - welcome
      • Write an element
        • Exercise - badmod
        • Exercise - abde
        • Exercise - charismatic
        • Exercise - sorting
      • Methods
        • index method
        • count method
        • Exercise - fruits
      • Exercises with functions
        • Exercise - touples
        • Exercise - joined
      • Verify comprehension
        • doubles
        • nasty
      • References
    • Sets
      • Download exercises zip
      • What to do
      • Creating a set
        • Converting sequences to sets
        • Mutable elements and hashes
        • Empty set
        • Exercise - dedup
        • Frozenset
      • Operators
        • len
        • Exercise - distincts
        • Union
        • Exercise - everythingbut 1
        • Intersection
        • Difference
        • Symmetric difference
        • Membership
          • not in
      • Equality
      • Methods like operators
        • union
        • update
        • Exercise - everythingbut 2
      • Other methods
        • add method
        • remove method
        • Exercise - bababiba
        • discard method
        • Exercise - trash
        • issubset method
        • issuperset method
        • isdisjoint method
      • Exercise - matrioska
      • Exercise with functions
        • Exercise - syllabs
        • Exercise - distinguish
      • Verifify comprehension
        • Exercise - intersectron
      • References
    • Dictionaries 1: Introduction
      • Download exercises zip
      • What to do
      • Creating a dictionary
        • The keys
          • Keys are immutable
          • Keys don’t have order
          • Key duplicates
        • The values
        • Empty dictionary
        • Keys and heterogenous values
      • Dictionary from a sequence of couples
      • Dictionary from keyword arguments
      • Copying a dictionary
        • Shallow copy
        • Deep copy
      • Continue
    • Dictionaries 2: Operators
      • Download exercise zip
      • What to do
      • len
      • Reading a value
        • Fast disorder
        • Exercise - z7
      • Writing in the dictionary
        • Writing - adding key/value
        • Writing - reassociate a key
        • Exercise - workshop
        • Writing - deleting
        • Exercise - desktop
        • Exercise - garden
        • Exercise - translations
      • Membership with in
        • not in
      • Dictionaries of sequences
      • Exercise - loans
      • Equality
        • Equality and order
        • Equality and copies
      • Exercise - ZOOM DOOM
      • Continue
    • Dictionaries 3: Methods
      • Download exercise zip
      • What to do
      • keys method
        • Exercise - messy keys
        • Exercise - sorted keys
        • Exercise - keyring
      • values method
      • Exercise - one by one
      • Exercise - bag
        • Exercise - common values
        • Exercise - small big
      • items method
        • Exercise - union without update
      • update method
      • Exercise - axby
      • Classes - OrderedDict
        • Exercise - phonebook
      • Exercise - OrderedDict copy
      • Classes - Counter
      • Exercise - saddened
      • Continue
    • Control flow 1: if
      • Download exercises zip
      • What to do
      • The basic command if else
      • else is optional
      • Exercise - no fuel
      • The command if - elif - else
        • Questions
      • Questions - Are they equivalent?
        • Are they equivalent? - strawberries
        • Are they equivalent? - max
        • Are they equivalent? - min
        • Are they equivalent? - big small
        • Are they equivalent? - Cippirillo
        • Exercise - farm
        • Exercise - accents
        • Exercise - Arcana
      • Nested ifs
        • Exercise - abscissae and ordinates 1
        • Esercise - abscissae and ordinates 2
        • Exercise - bus
        • Exercise - chronometer
      • Questions - Are they equivalent?
        • Are they equivalent? - inside outside 1
        • Are they equivalent? - stars planets
        • Are they equivalent? - green red
        • Are they equivalent? - circles squares
        • Are they equivalent? - inside outside 2
        • Are they equivalent? - Ciabanga
        • Exercise - The maximum
      • Ternary operator
        • Questions ternary ifs
        • Exercise - shoes
        • Exercise - the little train
      • References
    • Control flow 2: for
      • Download exercises zip
      • What to do
      • Iteration by element
        • Names of variables in for
        • Iterating strings
        • Iterating tuples
        • Questions - iteration
        • Exercise - magic carpet
        • Esercise - evensum
        • Exercise - birbantello
        • Exercise - articulate
        • Exercise - gala
        • Exercise - balance
      • Counting with range
        • Questions - range
        • Exercise - printdoubles
        • Exercise - multiples or not
        • Exercise - ab interval
      • Iterating by index
        • Exercise - kitchen
        • Exercise - neon
        • Exercise - emotions
        • Exercise - organetto
        • Exercise - sghiribizzo
        • Exercise - dna
        • Exercise - sportello
        • Exercise - farm
        • Exercise - pokemon
      • Modifying during iteration
        • Exercise - duplicate
        • Exercise - hammers
        • Exercise - Orangutan
        • Exercise - basket
      • Iterating a set
        • Questions - sets
      • Iterating a dictionary
        • Dictionary iteration - questions
        • Questions - Are they equivalent?
        • Are they equivalent ? postin
        • Are they equivalent ? cortel
        • Are they equivalent ? - gel
        • Are they equivalent ? - giri
        • Are they equivalent - Found
        • Exercise - color of hearts
        • Exercise - jewels
        • Exercise - powers
        • Exercise - flowers
        • Exercise - art
        • Exercise - stationery stores
        • Exercise - legumes
        • Exercise - sports
        • Modifying a dictionary during iteration
        • Exercise - zazb
      • Nested for
        • Questions - nested for
        • Exercise - casting
        • Exercise - cover the plane
        • Exercise - triangular
        • Exercise - port
        • Exercise - polygons
        • Exercise - bon jour
      • break and continue commands
        • Terminate with break
        • Jumping with continue
        • Combining break and continue
        • Questions - break and continue
        • Exercise - autonomous walking
        • Exercise - breaking bad
        • Exercise - breaking point
        • Exercise - breakdance
    • Control flow 3: while
      • Download exercises zip
      • What to do
      • Introduction
        • Terminating while
        • Non terminating while
        • Questions
        • Esercises - introduction
        • Exercise - printeven
        • Exercise - average
      • break and continue commands
        • Terminate with a break
        • Jumping with continue
        • Questions about break and continue
        • Exercise - findchar
      • Questions - Are they equivalent?
        • Are they equivalent? - BORG
        • Are they equivalent? - until 3
        • Are they equivalent? - by chance
        • Are they equivalent? - until six
        • Are they equivalent? - countdown 1
        • Are they equivalent? - countdown 2
        • Are they equivalent? - sorcery
        • Are they equivalent? - ping pong
        • Are they equivalent? - zanna
        • Are they equivalent? - pasticcio
      • Exercises - counters
        • Exercise - don’t break 1
        • Exercise - don’t break 2
        • Exercise - Give me a break
        • Exercise - paperboard
        • Exercise - until ten
        • Exercise - cccc
        • Exercise - converge
        • Exercise - wow
        • Exercise - Wild West
      • Modifying sequences
        • Stack - Drawing from a card deck
        • Stack - Drawing until condition
        • Exercise - Don’t break my heart
        • Questions - what happens?
        • Questions - are they equivalent?
        • Are they equivalent? - train
        • Are they equivalent? - append nx
      • Exercises - stack
        • Exercise - break sum
        • Exercise - travelbook
        • Exercise - BANG !
        • Exercise - Growing or degrowing?
      • References
    • Sequences and comprehensions
      • Download exercises zip
      • What to do
      • Iterables - lists
      • iterables - range
      • Materializing a sequence
        • Questions - range
      • reversed
        • Iterating with next
        • Exercise - sconcerto
        • Materializing an iterator
      • sorted
        • Exercise - reversort
      • zip
        • Exercise - ladder
      • List comprehensions
        • List comprehensions on strings
      • Questions - List comprehensions
      • Exercises - list comprehension
        • Exercise - power
        • Exercise - root
        • Exercise - first chars
        • Exercise - don’t worry
        • Exercise - greater than 3
        • Exercise - even
        • Exercise - both ends
        • Exercise - dashes
        • Exercise - lollosa
        • Exercise - dog cat
        • Exercise - smurfs
        • Exercise - precious metals
      • Filtered list comprehensions
      • Questions - filtered list comprehensions
      • Exercises - filtered list comprehensions
        • Exercise - savannah
        • Exercise - puZZled
      • References
    • Matrices: list of lists
      • Download exercises zip
      • Introduction
      • What to do
        • Overview
      • Exercises
        • Matrix dimensions
      • Extracting rows and columns
        • How to extract a row
        • Extracting row pointers
        • extrowf
        • Extract row with range
        • Extract row with a slice
        • Extract row with list comprehension
        • Extract column with a for
        • Extract column with a list comprehension
      • Creating new matrices
        • empty matrix
        • empty_matrix the elegant way
        • deep_clone
      • Modifying matrices
        • fillc
        • fillx
        • fillz
        • stitch_down
        • stitch_up
        • stitch_right
        • threshold
        • swap_rows
        • swap_cols
      • Other exercises
        • diag
        • anti_diag
        • is_utriang
        • stitch_left_mod
        • transpose_1
        • transpose_2
        • lab
        • dump
        • matrix multiplication
        • check_nqueen
    • Matrices: Numpy
      • Download exercises zip
      • Introduction
        • What to do
      • np.array
      • NaNs and infinities
        • NaNs
        • Detecting NaN
        • Sequences with NaNs
        • Exercise NaN: two vars
        • Operations on NaNs
        • NaN and Numpy
        • Where are the NaNs ?
        • Infinities
        • Positive infinity np.inf
        • Negative infinity
        • Combining infinities and NaNs
        • Negative zero
        • Exercise: detect proper numbers
        • Exercise: guess expressions
      • Verify comprehension
        • odd
        • doublealt
        • frame
        • chessboard
        • altsum
        • avg_rows
        • avg_half
        • matxarr
        • quadrants
        • matrot
      • References
        • Other Numpy exercises
    • Matrices: Numpy images
      • Download exercises zip
        • What to do
      • Introduction
        • Monochrome
      • Focus
        • Exercise - Head focus
      • hstack and vstack
        • Exercise - Passport
      • flip
        • Exercise - Too many
        • Exercise - The nose from above
      • Writing arrays
      • Writing into images
        • Exercise - Stripes
      • In a dark integer night
        • The Integer Shining
        • Exercise - Be bright
      • RGB - Get colorful
      • Exercise - Focus - top left
      • Exercise - Focus - bottom - left
      • Exercise - Focus - bottom - right
      • Exercise - Focus - top - right
      • Exercise - Look the other way
      • Exercise - Upside down world
      • Exercise - Shrinking Walls - X
      • Exercise - Shrinking Walls - Y
      • Exercise - Shrinking World
      • Exercise - Pixellate
      • Exercise - Feeling Red
      • Exercise - Feeling Green
      • Exercise - Feeling Blue
      • Exercise - No Red
      • Exercise - No Green
      • Exercise - No Blue
      • Exercise - Feeling Gray again
      • Exercise - Beyond the limit
      • Exercise - Gimme light
      • Exercise - When the darkness comes - with a warning
      • Exercise - When the darkness comes - without a warning
      • Exercise - Fade to black
      • Exercise - vertical fade
    • Errors and testing
      • Download exercises zip
      • Introduction
        • What to do
      • Unforeseen situations
        • make_problematic_pie
      • Check with the return
      • Exceptions
        • Manage exceptions
        • Particular exceptions
      • assert
        • When to use assert?
      • Testing
        • Where Is Your Software?
      • Testing with asserts
        • Exercise structure
        • even_numbers example
          • Let’s add assertions
        • Error kinds
          • Error kind a) An external user misuses you program.
          • Error kind b): Your code is just plain wrong
    • Commandments
      • I COMMANDMENT
      • II COMMANDMENT
      • III COMMANDMENT
      • IV COMMANDMENT
      • V COMMANDMENT
      • VI COMMANDMENT
      • VII COMMANDMENT
      • VIII COMMANDMENT
      • IX COMMANDMENT
      • X COMMANDMENT
  • B - Data analysis
    • Data formats (CSV, JSON)
      • Download exercises zip
      • Introduction
        • What to do
      • 1. line files
        • open command
        • The encoding
        • with block
        • people-complex line file:
        • Exercise - line file immersione-in-python-toc
      • 2. CSV files
        • Why parsing a CSV ?
        • Reading a CSV
          • What’s a reader ?
          • Consuming a file
          • Reading as dictionaries
        • Writing a CSV
        • Reading and writing a CSV
        • CSV Botteghe storiche
        • Problem: wrong characters ??
        • Botteghe storiche in Python
        • Botteghe storiche - rank_categories
        • Botteghe storiche - enrich
      • 3. JSON files
        • JSONL
    • Graph formats
      • Download exercises zip
      • Introduction
        • What to do
        • Required libraries
        • Graph definition
        • Edge weights
      • Matrices
        • Visualization examples
        • Saving a graph to an image file
        • Saving a graph to an dot file
        • Minimal graph
        • Graph with two nodes example
        • Distance matrix
        • Boolean matrix example
        • Matrix exercises
        • Exercise - line
        • Exercise - cross
        • union
        • Exercise - union
        • Subgraph
        • Exercise - is_subgraph
        • Exercise - remove_node
        • Exercise - utriang
        • Edge difference
        • Exercise - ediff
        • Exercise - pyramid
      • Adjacency lists
        • Exercise - mat_to_adj
        • Exercise - mat_ids_to_adj
        • Exercise - adj_to_mat
        • Exercise - table_to_adj
      • Networkx
        • Converting networkx graphs
        • Exercise - mat_to_nx
      • Simple statistics
        • Outdegrees and indegrees
        • Exercise - outdegree_adj
        • Exercise - outdegree_mat
        • Exercise - outdegree_avg
        • Exercise - indegree_adj
        • Exercise - indegree_mat
        • Exercise - indegree_avg
        • Was it worth it?
        • Exercise - min_outdeg
        • networkx Indegrees and outdegrees
    • Binary relations
      • Download exercises zip
      • What to do
      • Reflexive relations
        • Exercise - is_reflexive_mat
        • Exercise - is_reflexive_adj
      • Symmetric relations
        • Exercise - is_symmetric_mat
        • Exercise - is_symmetric_adj
      • Surjective relations
        • Exercise - surjective
      • Further resources
    • Visualization
      • Download exercises zip
      • Introduction
        • What to do
      • First example
        • Plot style
        • x power 2 exercise
        • Axis limits
        • Axis size
        • Changing tick labels
      • Introducting numpy
        • Example without numpy
        • Example with numpy
        • y = sin(x) + 3 exercise
        • Showing degrees per node
        • indegree per node
      • Bar plots
        • indegree per node bar plot
        • indegree per node sorted alphabetically
        • indegree per node sorted
        • out degrees per node sorted
        • degrees per node
      • Frequency histogram
      • Showing plots side by side
        • Graph models
          • Erdős–Rényi model
      • Other plots
        • Pie chart
      • References
    • Visualization - The AlgoRythm Opera Challenge
      • Download exercises zip
      • The variables
      • 1. plot_sheet
      • 2. plot_pentagram
      • 3. plot_notes
      • Final result 1
      • Final result 2
    • Pandas analytics
      • Download exercises zip
      • 1. Introduction
        • What to do
        • Check installation
      • 2. Data analysis of Astro Pi
        • 2.1 Exercise: meteo info
      • 3. Indexing, filtering, ordering
        • 3.1 Exercise: Meteo stats
      • 4. MatPlotLib review
        • Matplotlib plots from pandas datastructures
      • 5. Calculating new columns
        • 5.1 Exercise: Meteo Fahrenheit temperature
        • 5.2 Exercise: Pressure vs Temperature
      • 6. Object values
        • Filter by textual values
        • Extracting strings
      • 7. Transforming
      • 8. Grouping
      • 9. Exercise: meteo average temperatures
        • 9.1 meteo plot
        • 9.2 meteo pressure and raining
        • 9.3 meteo average temperature
      • 10. Merging tables
        • Exercise 10.1 better merge
      • Continue
      • References
    • Pandas analytics - EURES Job Offers
      • Download exercises and solution
        • What to do
      • offerte dataset
      • rename columns
      • 1. Rename countries
        • 1.1 countries_to_list
        • 1.2 Filling column Workplace Country
      • 2. Work dates
        • 2.1 from_to function
        • 2.2. From To columns
      • 3. Required languages
        • 3.1 function reqlan
        • 3.2 Languages column
    • Pandas analytics challenge - Italian poets
      • Download exercises
        • What to do
      • Load the dataset
      • Tell me more
      • Getting in shape
      • 10 rows
      • Born in Verona
      • How many people in Verona
      • Python is everywhere
      • Verona after 1500
      • First Antonio
      • Some Antonio
      • Cesares during 1800
      • Sorting
      • Where poets are born
      • Duplicated poets
  • Index
Next

© Copyright # CC-BY 2017 - 2020, David Leoni, Alessio Zamboni, Marco Caresia

Built with Sphinx using a theme provided by Read the Docs.