Use dict.setdefault() instead of try/KeyError pattern


Recently reminded (by ./modunite) of this nicer pattern, I went
looking for more places to apply it.

Change-Id: Ic14399d8d7afc91d4e339f237f543da1b35f41d6
Reviewed-by: Mate Barany <mate.barany@qt.io>
commit49487e6139d5f85fe497480fc152ae55a7befbb5
parent04625fb088264beae583c4d770e920f436727931
authorEdward Welbourne <edward.welbourne@qt.io>
committerEdward Welbourne <edward.welbourne@qt.io>
commit timeWed, 15 May 2024 13:47:00 +0200