Search⌘ K

Solution Review: Add Elements to the List

Explore adding elements to lists by comparing PowerShell and Python methods. Understand the use of the Add function in PowerShell and the append method in Python to effectively modify list data structures and print results.

Solution

Let’s understand the solution of the challenge in Powershell and Python.

Powershell

Python 3.5
$l = [System.Collections.ArrayList]::new()
1,3,5,7|` ForEach-Object {$l.Add($_) > $null} # Initialising list in Powershell
$l.Add(9) | Out-Null
$l.Add(11) | Out-Null
$l -join ' '

Explanation:

Line ...