Update detect.py

This generator causes an error in detect_windows because it is run twice there.
Better store it as a data structure instead.
Merge pull request #1198 from dbbert/patch-1
Back-merge to include #1198