Skip to content

Commit c01b9f2

Browse files
colinleachColin Leach
and
Colin Leach
authored
Add bit on comprehensions to vector-operations (#885)
* concepts.wip exercises changed to deprecated * Revert "concepts.wip exercises changed to deprecated" This reverts commit 28f91a8. * Change annelyns-infiltration slug for old version * Revert "Change annelyns-infiltration slug for old version" This reverts commit 09dfe5d. * add brief mention of array comprehensions --------- Co-authored-by: Colin Leach <[email protected]>
1 parent b0d5668 commit c01b9f2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

concepts/vector-operations/about.md

+22
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,27 @@ julia> a[condition]
247247
'C': ASCII/Unicode U+0043 (category Lu: Letter, uppercase)
248248
```
249249

250+
## Comprehensions
251+
252+
Anyone who likes list comprehensions in Python will be pleased to know that Julia uses [similar syntax][comprehensions].
253+
254+
```julia-repl
255+
julia> [n for n in 1:10 if n%3 == 0]
256+
3-element Vector{Int64}:
257+
3
258+
6
259+
9
260+
261+
julia> [uppercase(c) for c in "Julia" if c > 'h']
262+
3-element Vector{Char}:
263+
'U': ASCII/Unicode U+0055 (category Lu: Letter, uppercase)
264+
'L': ASCII/Unicode U+004C (category Lu: Letter, uppercase)
265+
'I': ASCII/Unicode U+0049 (category Lu: Letter, uppercase)
266+
```
267+
268+
_Similar_ syntax, but not _identical_.
269+
There is some divergence for multiple variables and/or multi-dimensional arrays, so this topic will be covered in more detail in a later Concept.
270+
250271
[vectors]: https://exercism.org/tracks/julia/concepts/arrays
251272
[ranges]: https://exercism.org/tracks/julia/concepts/ranges
252273
[sets]: https://exercism.org/tracks/julia/concepts/sets
@@ -255,3 +276,4 @@ julia> a[condition]
255276
[zip]: https://docs.julialang.org/en/v1/base/iterators/#Base.Iterators.zip
256277
[bitarray]: https://docs.julialang.org/en/v1/base/arrays/#Base.BitArray
257278
[broadcasting]: https://docs.julialang.org/en/v1/manual/arrays/#Broadcasting
279+
[comprehensions]: https://docs.julialang.org/en/v1/manual/arrays/#man-comprehensions

0 commit comments

Comments
 (0)