Jan-09-2018, 08:48 AM
The generator reuses the reference to the list subdirs in subsequent steps. It means that any change of the list's content will be reflected in the subdirs' walk. Look at this code
>>> a = ['spam', 'eggs', 'ham'] >>> b = a >>> a[:] = sorted(a) >>> b ['eggs', 'ham', 'spam'] >>> >>> >>> a = ['spam', 'eggs', 'ham'] >>> b = a >>> a = sorted(a) >>> b ['spam', 'eggs', 'ham']Using
a[:] =
changes list a
in place, while a =
doesn't change the initial list.