Dynamic typing keeps data strongly typed while leaving variables without fixed types. A name can refer to values of different types, enabling one generic function instead of several type-specific versions. section 4.5 section 4.2
Build one function for several sequence types
Use the shared sequence operations—indexes and slices—to write one function for strings, lists, tuples, and compatible user-defined types: ```python def firstlast(sequence): return sequence[:1] + sequence[-1:] firstlast('abc') # 'ac' firstlast([1, 2, 3, 4]) # [1, 4] firstlast((1, 2, 3, 4))# (1, 4) ``` Indexing retrieves individual elements, which may have any type. Slicing returns the same sequence type, making slice concatenation the suitable strategy here. section 4.2 section 4.3
Apply the same strategy when:
- One operation should handle integers and floats rather than separate numeric functions. section 4.5
- A function should work across strings, lists, tuples, files, or testing simulators that support the required operations. section 4.5
- Practice with even-odd sums, alternating addition and subtraction, thresholded sums, integer conversion, or dictionary merging. section 4.5 section 4.9





