<s>[INST] Given a string `s` and an integer `k`, return the length of the longest substring of `s` that contains exactly `k` distinct characters. For example, given `s = "eceba"` and `k = 2`, the longest substring with exactly `2` distinct characters is `"ece"`, which has a length of `3`.

My solution is:

```python
def longest_substring_two_distinct(s, k):
    start = 0
    max_length = 0
    dist_count = {}
    
    for end in range(len(s)):
        if s[end] not in dist_count:
            dist_count[s[end]] = 0
        dist_count[s[end]] += 1
        
        while len(dist_count) > k:
            dist_count[s[start]] -= 1
            if dist_count[s[start]] == 0:
                del dist_count[s[start]]
            start += 1
        
        max_length = max(max_length, end - start + 1)
    
    return max_length
```

How can I make this solution more Pythonic and idiomatic?[/INST]