MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/PowerShell/comments/iuifz8/powershell_vs_python_reference/g5kymli/?context=3
r/PowerShell • u/[deleted] • Sep 17 '20
51 comments sorted by
View all comments
5
Does powershell have something like python's list comprehension?
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] print(a[1:10:2])
6 u/bozho Sep 17 '20 It does, not always as terse as Python. Your example could be written as:$a = @(1..10) $a | ? { $_ % 2 -eq 0 }I don't think there's a nice syntax to select every Nth element though. On the other hand, you can use LINQ for that :-)
6
It does, not always as terse as Python. Your example could be written as:
$a = @(1..10) $a | ? { $_ % 2 -eq 0 }
I don't think there's a nice syntax to select every Nth element though. On the other hand, you can use LINQ for that :-)
5
u/prp7 Sep 17 '20
Does powershell have something like python's list comprehension?