31   Working with List: filtering

After reading this lesson, you will be able to:

  • Remove or select items from a sequence based on their position
  • Filter elements of a list that respect a given predicate
  • Remove duplicated items in a sequence

In the previous lesson, you have learned how to select a single element in a sequence based on its position or features. In this lesson, you are going to continue to discover other operations you can perform on an instance of List. In particular, you will see how you can use an existing list to create a new one by selecting one of its subsections. You will discover how to pick elements that have specific characteristics. Finally, you will learn how to create a new sequence that contains no duplicated items. In the capstone, you will use these operations to create a subset of movies that have specific characters.

31.1   Dropping and Taking elements

In the previous lessons, you have been developing a program to store your contacts. Let’s recall that your program represents a contact record as following:

31.2   Filtering Items of a List

31.3   Removing duplicates

31.4   Summary

31.5   Answers to Quick Checks