Melody Structures
create melody
We can create melodies by coding structures to hold pitch data. These structures are like sequence of
boxes, with each box holding some data, or a pitch, inside. Let's code some melodies.
Let us first create a melody using a list of notes.
Create a list and access an element with [ ] ( remember, elements start at 0 ) :
edit melody
Lists are mutable, meaning we can change or mutate them. Let's make some changes.
Try adding some stuff with append( ) and extend( ),
and then take something off of the list with pop( ):
2 or more lists can be added together to form a new list:
save tuning
If we would like to save our tuning, we can save it as a set of pitches. The set mutable, kind of like lists, except
in a set, every kind of thing can only appear once.
Set example:
Dictionaries are some of the most powerful Python data structures. They hold data in key value pairs.
construct dictionary and get value y by key x
Control Flow
Create loop
Loops are not data structures; rather, they are control structures, or structures for controlling other
structures. Lets loop through a list and run each note
Functions
Create Functions
Functions are blocks of organized code that run when given a push.
We're going to build different types of functions.
simple function examples:
Lambda functions are anonymous functions.
construct lambda function:
construct filter lambda
filter DataFrame with lambda
construct map lambda
construct reduce lambda