How to improve this code

Is this a homework problem?

In a real-life application, I would consider the following first:

  1. choose another datastructure for buses, eg a struct or a NamedTuple,
  2. don’t convert to strings for keys, use i directly,
  3. wrap the whole thing in a function, and just pass data["bus"] to it,
  4. think about returning the whole bus datastructure instead of key (but this depends on the context)
  5. use a standard idiom like findall or filter for getting buses of a given type (are they unique by type?)

See the manual for all of these.

An alternative is just dumping everything in a dataframe using a “tidy” structure. See

https://juliadata.github.io/DataFrames.jl/stable/

3 Likes