Advanced Topics in Python

In this section we learned to manipulate dictionaries and lists, specifically slicing and iterating over them. The last topic covered in this section was the use of lambda expressions, which ultimately lets you create a temporary function without having to write a block of code beneath it.

atp15

On the slide above, Iterating Over Dictionaries , we practiced invoking the keys and items in a dictionary. Such as using the command “print movies.keys()” to call all of the expressions we set equal to a value.

atp16

In the next slide, Comprehending Comprehension, we had to create a list of numbers from 1-16, and then manipulate it so that when printed it would only print numbers divisible by 3 or 5.   This was accomplished using functions like range, to create the number line, and the “%” function which checks if the numbers are evenly divisible by a designated number.

atp17

Slide 17, “List Slicing”, dealt mainly with editing strings. In the example above you can see the message is mixed with a number of X’s, and the objective was to extract this message letter by letter. The way to accomplish this is by using the command [start:end:stride]. The start portion of this command selects a starting point, the end portion selects the end point, and the stride determines how often it selects a letter to extract.

atp18

The final exercise “Lambda Expressions”, introduced the use of the lambda command, which allows the user to create a temporary function without having to define it’s rules or write and code to instruct it. Lambda functions are set up as follows: lambda x:…. They work by setting x equal to a parameter for it to search for, such as x %3 == 0, which would search for all numbers that are evenly divisible by 3.