November 2017
Beginner
316 pages
6h 40m
English
List comprehensions are frequently used and make populating arrays easier. Let's create an array using list comprehension, where we will populate it with the power of 2:
# create an array of size 10julia> pow2 = Array(Int64,10)10-element Array{Int64,1}:...# assign 2 to the first elementjulia> pow2[1] = 22# using list comprehension populate it with powers of 2julia> [pow2[i] = 2^i for i = 2:length(pow2)]; pow210-element Array{Int64,1}: 2 4 8 16 32 64 128 256 5121024
List comprehension can prove to be very powerful and convenient in various scenarios.
Read now
Unlock full access