Python's features, which requires D

Dennis Ritchie via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 21 19:27:44 PDT 2015


On Friday, 22 May 2015 at 02:18:23 UTC, weaselcat wrote:
> On Friday, 22 May 2015 at 01:52:30 UTC, Dennis Ritchie wrote:
>>> off the top of my head, the last one can easily be done with 
>>> std.range.stride
>>
>> import std.stdio, std.range;
>>
>> void main()
>> {
>>    int[] a = [ 1, 2, 3, 4, 5, 6 ];
>>
>>    writeln(stride(a, 2)); // [1, 3, 5] #odd #print(x[::2]) #OK
>>    // [2, 4, 6] #even #print(x[1::2]) #no equivalent in D
> writeln(stride(a[1..$], 2));
>>
>>    auto x = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];
>>    // [2, 6, 10] #print(x[1::4]) #no equivalent in D
> writeln(stride(a[1..$], 4));
>> }

Yes, this is what you need (I often forget that the functions can 
take ranges in D).

Maybe somewhere and nested loops "for" to fill the arrays lying 
around :)


More information about the Digitalmars-d-learn mailing list