I don’t know whether this trick has already been mentioned:
In the Finder, in List view, you can navigate using the up/down arrow keys. Now that’s well known. If the selection highlights a folder, pressing the right arrow key expands the folder (same as clicking on the “open” triangle symbol on the left side of the folders name).
Pressing the left arrow key collapses the folder again. If the selection highlights a document in an expanded folder, pressing the left arrow key moves the selection up to the containing folder, which then can be collapsed by pressing the left arrow key a 2nd time.