How could we have initialized myphonebook so that it would accept integers as values?


#1

myphonebook = Dict(“Jenny” => “867-5309”, “Ghostbusters” => “555-2368”)


#2

Just use integers instead of strings.


#3

Will that always evaluate the -


#4

Yes, since an integer cannot contain -.
What exactly do you want to do?

Maybe you are asking how to remove the - from a string. You can do that eg with the replace function, and then use the parse function to convert it to an integer.


#5
parse(Int, replace("555-1234", r"\D"=> ""))

Feature creep: :wink:

julia> parse(Int, replace("+1(800)555-1234", r"\D"=> ""))
18005551234

#6
parse(Int, replace("555-1234", "-" => ""))

#7

Is this your home work assignment?


#8

no, it just is a exercise, i learn it by myself