r/PowerShell • • Sep 17 '20

PowerShell vs Python Reference

https://blog.ironmansoftware.com/powershell-vs-python/
206 Upvotes

51 comments sorted by

View all comments

5

u/prp7 Sep 17 '20

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])

1

u/HeKis4 Sep 17 '20

Afaik it doesnt. Your code would either filter out every other element like what has already been posted or use a for loop with $i += 2 at the end.