30 Working with List: element selection
After reading this lesson, you will be able to:
- Select the first element of a sequence if any
- Pick the nth item of a list
- Find the first element of a sequence that respects a given predicate
- Find the minimum/maximum item in a list according to some criteria
In the previous lesson, you have learned how to analyze the properties of a sequence. In this lesson, you have going to see how to select one item in a list. In particular, you are going to see how to pick an element by its position. You are also going to discover how to find an item that has specific characteristics. Finally, you are going to learn how to pick the minimum or maximum element in a list based on a natural ordering or custom ordering criteria. In the capstone, you are going to analyze the Movies Dataset to determine which movie has the highest profit.
30.1 Selecting an element by its position
Let’s continue to expand the functionalities of your address book program, in which each contact as represented as the following: