Schwartzian Transform in Python?
Gordon McMillan
gmcm at hypernet.com
Thu Apr 27 14:22:01 EDT 2000
Art Haas wrote:
>
> I'm looking for the Python way to do this ...
>
> opendir(DIR,".") || die "Can't open '.'! $!\n"
> @sorted =
> map { $_->[0] }
> sort { $a->[1] <=> $b->[1] }
> map { [ $_ , -M ]} readdir(DIR)
> closedir(DIR);
> print "Files sorted by date ...\n";
> foreach (@times) {
> print "$_\n";
> }
>
> (Yes, its that other 'P' language).
>
> I'm getting lost in the map/sort/map part for python. My python
> psuedo code looks like (don't laugh too much)
>
> import os
> sorted = map(???,(map(os.stat???,listdir(".").sort())))
> print "Files sorted by date ..."
> for file in sorted:
> print file
>>> import os, stat
>>> l = map(lambda f: (os.stat(f)[stat.ST_MTIME], f),
os.listdir('.'))
>>> l.sort()
>>> for (t,f) in l:
... print f
Don't speak that other language, so I'm taking what you said
you want at face value...
- Gordon
More information about the Python-list
mailing list