Posts

Showing posts with the label Lists

Indexing tuples and lists that contain tuples and lists: BEHIND THE SCENES!

Image
Indexing Tuples and Lists that contain Tuples and Lists Hi! Welcome to this  “Indexing tuples and lists”  tutorial. We will be covering the principles behind  indexing tuples and lists that contain tuples and lists as elements  (they can also contain other data types, we’ll see an example of this right away). Presenting the examples we will be working with! As promised! Here are the two examples we will be working with during this tutorial. As you can see, we have a list and a tuple but the curious thing about them is that some of their element are also lists and tuples. NOTE:  In these examples lists contain lists and tuples contain tuples, but lists can contain tuples as well and viceversa Finding an element in this data structure Let’s analyze the question presented in the slide above by following the diagram below. “How can we find  "house3"  in  List1 ? We’ll start by  breaking down the structure of ...

Iterating over Lists and Tuples: BEHIND THE SCENES!

Image
Hi! Welcome to this section. This time, we will discuss iterables. During your problem sets you will discover the power of iterables and how they can completely change you software development thinking process. Formally, an iterable is "an object capable of returning its members one at a time . Some data types we have studied are iterables, as you can see in the slide below. Strings and lists and tuples are iterables. And later on you will study Dictionaries (you can iterate over their keys and their corresponding values). You can find more on iterables in Python's documentation:   https://docs.python.org/3.6/glossary.html But this concept seems so abstract, right? “Capable of returning its members one at a time” What does this mean? Iterables’ magic comes to life in for loops . Why? Because they return their elements one at a time on every iteration. This is better illustrated with an example to describe the required syntax: Iterables in Action!...