-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Added getindex(t::Associative, keys...) #4803
Conversation
* convenience function for [getindex(d, key) for key in keys]
I think this is too random. Nothing about passing multiple arguments
|
@JeffBezanson, I'm confused... it sounds like you don't like it, but you like it... ;-) I added an example here. I can see @JeffBezanson's point that there is no precedence for multiple indices producing an array. I still feel that this is reasonable behavior for dictionaries, but I'm good with whatever. |
This is the kind of feature where I think it is better to say no than to say yes, because it can be added at any time later, but it can't be removed. It is also a feature most developers will not know about and I think it has a low guessability factor, so programmers will spend time figuring out what happens when they read other peoples code. The comprehension syntax is not many characters more to write, and if someone finds it unfamiliar they will get more back for their time trying to understand comprehensions. |
Yeah, I'm afraid I'm not a fan – I don't even really like the resulting syntax all that much – I prefer the comprehension. |
Okay, no worries. |
Hi, I agree that the syntax resulting from that solution isn't ideal but I do like the functionality, and my experience is that it quite useful in text processing applications. I will admit that I am biased since my "go to" language is Perl, but I see that Julia would be very nice to use in a lot of text applications built around Topic Modeling which is computationally intensive, especially the MCMC implementations. I do appreciate that one wants to be very conservative in introducing special syntax, but perhaps it could be motivated for such a fundamental data type as Dictionaries. Best Regards |
Just to make sure there's no confusion: you already have the functionality available, through the comprehension syntax. |
@timholy: Yep, I'm with you on that! :) I'd just like as nice compact syntax for Dictionary slices as for Array slices, and I also like the symmetry of both Arrays and Dictionaries having a slice syntax. :) For sure, it is not something that will make or break Julia, but it is that type of convenience that at least I have come to expect of new dynamic languages. Cheers! |
Sorry I'm late to this discussion, but I would tend to prefer that
be equivalent to
which would give a nice syntax for the common case of dictionaries keyed by tuples of values. To put it another way, I think |
big +1 to @stevengj's proposal. |
Does that imply that |
No, that will return whatever is in the dictionary. |
I agree that @stevengj 's interpretation of |
No, not at all. That would still return the value associated with the array object |
FWIW, @stevengj's proposal is Python's behavior. |
That is usually an indication that it's a pretty sane choice. In this case, I didn't really need that indication though. As @JeffBezanson said, it's clearly the right behavior. |
OK, makes sense, but it's still slightly annoying that you need to use the comprehension syntax to extract several elements. Not a big deal of course. |
So, what will that look like in terms of usage patterns? Is there a reasonably terse syntax and efficient way in terms of performance to transform an array to tuples? I assume that most will have the dictionary keys in an array... |
@lejon, if you have an array |
Since multidimensional dictionaries seem unlikely, this seems okay to me, but others may reasonably feel that the comprehension syntax is sufficient.
See https://groups.google.com/forum/#!topic/julia-users/5bi3jgJgF8g for the discussion that prompted this.