[Issue 5968] Two changes for std.algorithm.group()?
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Feb 12 17:42:45 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=5968
--- Comment #1 from bearophile_hugs at eml.cc 2013-02-12 17:42:44 PST ---
I suggest to introduce a new function std.algorithm.groupFull that yields
tuples where the second field of the tuple is a lazy range of all the grouped
items, as in Python groupby.
This Python2 program returns all the longest words that have ordered chars:
from itertools import groupby
o = (w for w in map(str.strip, open("words.txt")) if sorted(w)==list(w))
print list(next(groupby(sorted(o, key=len, reverse=True), key=len))[1])
A similar program using groupFull:
import std.stdio, std.algorithm, std.range, std.file, std.string;
void main() {
"words.txt"
.readText()
.splitter()
.filter!isSorted()
.array()
.sort!q{a.length > b.length}()
.groupFull!q{a.length == b.length}()
.front[1]
.writeln();
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list