Dynamic typing lets variables refer to values of different types while functions operate on shared behavior rather than fixed declarations. Python therefore favors one generic function over several type-specific versions. section 3.1 section 3.5
One function for several sequence types
```python def firstlast(sequence): return sequence[0] + sequence[-1:] print(firstlast('abc')) # 'ac' print(firstlast([1, 2, 3, 4])) # [1, 4] print(firstlast((10, 20, 30)))# (10, 30) ``` The function relies on indexing and slicing, shared by strings, lists, and tuples. Its output keeps the input’s sequence type, avoiding separate implementations for each type. section 3.1 section 3.5
Practice the same flexible approach with functions that:
- Sum values above a threshold for numbers, strings, or other comparable types. section 3.10
- Convert integer-like arguments, ignore unconvertible values, and return their total. section 3.10
- Combine dictionaries while collecting repeated keys into lists. section 3.10





