Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 4: Collections #20

Open
sbromberger opened this issue Jan 7, 2015 · 2 comments
Open

Chapter 4: Collections #20

sbromberger opened this issue Jan 7, 2015 · 2 comments

Comments

@sbromberger
Copy link

Existence of a particular value

To find out whether an array has a particular value among its elements, you can use in():

    julia> in(2, primes)
    true
Somewhat strangely, in the in() syntax, the needle comes before the haystack, i.e. in(value, array), where value denotes the value you are looking for.

Why not talk about contains() as well, where the haystack comes first?

@sbromberger
Copy link
Author

Also,

Change values

To change a value, access it via the bracket syntax, then assign it the new value:

    julia> statisticians["Kendall"] = "1907-1983"
    "1907-1983"

    julia> statisticians
    Dict{ASCIIString,ASCIIString} with 4 entries:
      "Galton"  => "1822-1911"
      "Pearson" => "1857-1936"
      "Kendall" => "1907-1983"
      "Gosset"  => "1876-1937"

The example doesn't fit the previous contents of the Dict: you should be assigning "Gosset".

@sbromberger
Copy link
Author

Also,

This is because dicts are not indexable, therefore there is no ordering that would make inherent sense. However, sometimes, we like dictionaries sorted. Disappointingly, sorting dicts is not as easy as sorting arrays:

Perhaps a mention of DataStructures.jl?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant