Python's features, which requires D
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu May 21 22:31:37 PDT 2015
On 05/21/2015 05:23 PM, Dennis Ritchie wrote:
> Hi,
> I've collected some of Python's features. It seems to me that they are
> not in the D!
>
> Surely all this is in the D? :)
> http://rextester.com/CNQQR3333
Here is my attempt:
import std.stdio;
import std.algorithm;
import std.conv;
import std.range;
void main()
{
// Replace 'none' with 'all' to activate.
version (none) {
const n = 5;
auto a = stdin
.byLine
.map!(l => l.splitter.map!(to!int).array)
.take(n);
writeln(a);
writeln("-----");
}
{
const n = 6;
auto a = iota(n)
.map!(i => chain([2].replicate(i),
[1],
[0].replicate(n - i - 1)));
writefln("%(%(%s %)\n%)", a);
writeln("-----");
}
{
const x = [ 1, 2, 3, 4, 5, 6 ];
writeln(x.stride(2));
writeln(x.dropOne.stride(2));
writeln("-----");
}
{
// The internet does not need another fizz buzz. :p
}
}
Ali
More information about the Digitalmars-d-learn
mailing list