Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!/usr/bin/env python3 

2"""Solution to chapter 3, exercise 9: firstlast""" 

3 

4 

5def firstlast(sequence): 

6 """Given a sequence, returns a two-element sequence. 

7The returned sequence will be of the same type as the argument. 

8Its two elements will be the argument's first and last elements. 

9""" 

10 return sequence[:1] + sequence[-1:]