# Advanced Topics in Python

Learn some of the more complex aspects of Python, including data structures, list comprehensions, list slicing, and lambda expressions.

Start- 1
Let's start with iterating over a dictionary. Recall that a dictionary is just a collection of keys and values. [...] Note that the [...] method doesn't return key/value pairs in any specific...

- 2
While [...] returns an array of

*tuples*with each tuple consisting of a key/value pair from the dictionary:*The [...] method returns a list of the dictionary's keys, and*The [...] metho... - 3
For iterating over lists, tuples, dictionaries, and strings, Python also includes a special keyword: [...] . You can use [...] very [...] tuitively, like so: [...] 1. In the example above, ...

- 4
Let's say you wanted to build a list of the numbers from 0 to 50 (inclusive). We could do this pretty easily: [...] But what if we wanted to generate a list according to some logicâ€”for example,...

- 5
Here's a simple example of list comprehension syntax: [...] This will create a [...] populated by the numbers one to five. If you want those numbers doubled, you could use: [...] And if y...

- 6
Great work! Now it's time for you to create a list comprehension all on your own. [...] The example above creates and prints out a list containing [...] .

- 7
Sometimes we only want part of a Python list. Maybe we only want the first few elements; maybe we only want the last few. Maybe we want every other element! List slicing allows us to access elemen...

- 8
If you don't pass a particular index to the list slice, Python will pick a default. [...] 1. The default starting index is [...] . 2. The default ending index is the end of the list. 3. The d...

- 9
We have seen that a positive stride progresses through the list from left to right. A

*negative*stride progresses through the list from right to left. [...] In the example above, we print out... - 10
A positive stride length traverses the list from left to right, and a negative one traverses the list from right to left. Further, a stride length of 1 traverses the list "by ones," a stride lengt...

- 11
Great work! See? This list slicing business is pretty straightforward. Let's do one more, just to prove you really know your stuff.

- 12
One of the more powerful aspects of Python is that it allows for a style of programming called

**functional programming**, which means that you're allowed to pass functions around just as if they w... - 13
Lambda functions are defined using the following syntax: [...] Lambdas are useful when you need a quick function to do some work for you. If you plan on creating a function you'll use over and...

- 14
All right! Time to test out [...] and [...] expressions. [...] The example above is just a reminder of the syntax.

- 15
First, let's review iterating over a [...] .

- 16
Good! Now let's take another look at list comprehensions. [...]

- 17
Great! Next up: list slicing. [...] You can think of a Python string as a list of characters.

- 18
Last but not least, let's look over some [...] s. [...] We've given you another (slightly different) [...] . Sort it out with a [...] and a [...] .

- 1
Welcome to an intro level explanation of bitwise operations in Python! Bitwise operations might seem a little esoteric and tricky at first, but you'll get the hang of them pretty quickly. *Bitwis...

- 2
When we count, we usually do it in base 10. That means that each place in a number can hold one of ten values, 0-9. In binary we count in base two, where each place can hold one of two values: 0 or...

- 3
All right! Time to practice counting in binary. To make sure you've got the hang of it, fill out the rest of the numbers all the way up to twelve. Please

**do not**use the str() method or any oth... - 4
Excellent! The biggest hurdle you have to jump over in order to understand bitwise operators is learning how to count in base 2. Hopefully the lesson should be easier for you from here on out. Th...

- 5
Python has an [...] function that you've seen a bit of already. It can turn non-integer input into an integer, like this: [...] What you might not know is that the [...] function actually h...

- 6
The next two operations we are going to talk about are the left and right shift bitwise operators. These operators work by shifting the bits of a number over by a designated number of slots. The b...

- 7
The bitwise AND ( [...] ) operator compares two numbers on a bit level and returns a number where the bits of that number are turned on if the corresponding bits of

**both**numbers are 1. For exam... - 8
The bitwise OR ( [...] ) operator compares two numbers on a bit level and returns a number where the bits of that number are turned on if

**either**of the corresponding bits of either number are 1... - 9
The XOR ( [...] ) or

*exclusive or*operator compares two numbers on a bit level and returns a number where the bits of that number are turned on if**either**of the corresponding bits of the two ... - 10
The bitwise NOT operator ( [...] ) just flips all of the bits in a single number. What this actually means to the computer is actually very complicated, so we're not going to get into it. Just know...

- 11
A

*bit mask*is just a variable that aids you with bitwise operations. A bit mask can help you turn specific bits on, turn others off, or just collect data from an integer about which bits are on o... - 12
You can also use masks to turn a bit in a number on using [...] . For example, let's say I want to make sure the rightmost bit of number [...] is turned on. I could do this: [...] Using the ...

- 13
Using the XOR ( [...] ) operator is very useful for flipping bits. Using [...] on a bit with the number one will return a result where that bit is flipped. For example, let's say I want to flip...

- 14
Finally, you can also use the left shift ( [...] ) and right shift ( [...] ) operators to slide masks into place. [...] Let's say that I want to turn on the 10th bit from the right of the intege...

## What you'll create

Portfolio projects that showcase your new skills