Question:

Is it pythonic to pass a list of dictionary keys to iterate, BUT if an empty list is passed, iterate the entire dictionary?

If not suggestions please 😅

My only other approach is two methods, but as there are many features to process this way, it seems overly messy to me.

#python`

@kingfisher

In terms of actual function signature, it doesn't seem very Pythonic to me. This would be clearer, I think:

def process_dict(d: dict[str, str], keys: list[str] | None = None) -> whatever:

Having `keys` be a second, optional argument that defaults to None (so it can't be mistaken for a list) more strongly implies the purpose of that argument, I think. If you supply keys, process those, otherwise process the whole thing.

@cazabon Indeed that is a good function signature.

I have been lazy in both code and my question here and need to relearn+use those 'modern' function signatures and in syudy particular the optional value, ie ' | None = None' etc