# Generate all words of a given size from a fixed alphabet

**URL:** <https://discourse.julialang.org/t/generate-all-words-of-a-given-size-from-a-fixed-alphabet/20949>\
**Category:** General Usage\
**Created:** [February 18, 2019, 7:43pm UTC](https://discourse.julialang.org/t/generate-all-words-of-a-given-size-from-a-fixed-alphabet/20949 "2019-02-18T19:43:04Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [February 18, 2019, 9:14pm UTC](https://discourse.julialang.org/t/generate-all-words-of-a-given-size-from-a-fixed-alphabet/20949/4 "2019-02-18T21:14:47Z")

</div>

`Iterators.product` is actually already lazy. I collected it above since it sounded like that’s what OP wanted, but we can just as well iterate over it lazily:

```julia
alphabet = 'a':'d' # or "abcd"
k = 2

itr = Iterators.product(ntuple(_ -> alphabet, k)...)

for word in Base.Generator(join, itr)
    println(word)
    word == "bb" && break
end

```

Output:

```julia
aa
ba
ca
da
ab
bb

```

---

_[View the full topic](https://discourse.julialang.org/t/generate-all-words-of-a-given-size-from-a-fixed-alphabet/20949)._
