1 of 11

List Slicing

2 of 11

Agenda

  • What is list slicing?
  • Python list slicing
  • Practice

2

3 of 11

What is List Slicing?

This sounds ominous

1

4 of 11

What is List Slicing?

  • Lists are a powerful and fundamental part of Python
  • List slicing builds new lists out of existing lists
  • Part of any sequential data within Python
    • Lists
    • Strings
    • Ranges
    • Tuples

4

5 of 11

Python List Slicing

How to slice and dice in Python

2

6 of 11

Python List Slicing

  • List slicing uses the start:stop:step notation
  • Consider the following array and a slice

6

7 of 11

Slicing Options

  • Negative elements are counted down from the end of the list
  • Steps can be negative to count down
  • The start can also be skipped and assumed zero
  • The end can be skipped and assumed n

7

8 of 11

Reversing a List

8

9 of 11

Practice

Practice makes perfect

3

10 of 11

Practice

  • L3.01 Slices

10

11 of 11

Credits

Special thanks to all the people who made and released these awesome resources for free:

  • Presentation template by SlidesCarnival
  • Photographs by Unsplash

11