We’ve agreed that this concept is needed, and I ought to write it. Now I just need to get my old, tired brain fired up and actually write it. Let’s hope…
Dear Depial,
thanks for your detailed answer which is much much more than I could have ever expected!!
I agree in most of the cases
And find the idea of being
very good and very convincing.
but without
output = Array{Pair{String, Int64}}
it didn’t work…
I had permanent errors.
is there a simpler way of doing it?
I guess the sorting and related function is not such a big think… I just mentioned it to complete the explanations.
As I remember the
delete!
function can also be used on pairs (which user a key)
I can also agree to your explanations about having alternatives
So thanks again and have a nice evening and a good time!
with kind regards,
Nisang
You’re most welcome :)
In regards to:
I would guess there is another issue I’m not aware of without seeing what error was thrown. If you can share the error, it would help me debug. If it is related to the error you listed above:
ERROR: MethodError: no method matching append!(::Type{Array{Pair{String, Int8}}}, ::Pair{String, Int64})
I can see an couple of issues. However, I believe the main one is related to how you are using append!() in your code (it looks like it’s being used like push!()). However you’ve corrected that in your example later on.
I used your working example for list_inventory() from above and put it in my solution in place of my function and everything worked using just output = []. More specifically, the following version passes the tests in my solution:
function list_inventory(inventory)
output = []
@show typeof(output)
for (key, value) in inventory
if value == 0
delete!(inventory, key)
else
@show("append ",key => value)
push!(output, key => value)
# append!(output, [key => value])
end
end
sort(output)
end
So there may be an issue elsewhere?
As I remember the
delete!()function can also be used on pairs (which uses a key)
I would recommend you go back and read the introduction in a bit more detail. Pairs are distinct from Dicts and keys are mentioned in there somewhere.