|
gonadic io posted:if you split that up using 'where' and use 'filter' instead of list comprehensions, it becomes a lot clearer imo this looks awesome as hell and i feel like i suddenly "get it" thanks
|
# ? Nov 30, 2015 04:22 |
|
|
# ? May 22, 2024 09:40 |
|
nothing i post should be interpreted as a sign of interest in or approval of the iverson tradition
|
# ? Nov 30, 2015 05:01 |
|
Bloody posted:this looks awesome as hell and i feel like i suddenly "get it" thanks agreed this has been pretty helpful. Everyone talkin bout haskell has been helpful in fact. thanks guys
|
# ? Nov 30, 2015 05:43 |
|
Internet Janitor posted:would there be actual interest in an APL/J/K thread in CoC, or would it just be pages and pages of "this is unreadable", "what's with the funny symbols", etc Would read and participate! I have a colleague who works on a compiler for a statically typed APL dialect, and I hope to get involved at some point. It is an amazing language that I still do not understand fully. Gazpacho posted:arrays in haskell make me lol Arrays in most languages make me lol, they all get it wrong! For example, Haskell's Data.Array lets you define the index space as all sorts of crazy things. The way you define an N-dimensional array is to define an array where an index is a tuple of N integers. But then you cannot efficiently perform partial indices, e.g. index that N-dimensional array with a single integer to get an (N-1)-dimensional array. Data.Vector isn't better as I remember it. And no, using arrays of arrays is not the same thing, we are not primitive C programmers here. Arrays are surprisingly hard to get right, and I suspect they pretty much have to be a builtin to be both safe, performant, and expressive. (Fortran gets it right but gets so much more wrong.)
|
# ? Nov 30, 2015 07:12 |
|
Athas posted:Data.Vector isn't better as I remember it Last I checked, Data.Vector makes your index be an int and so disallows N-dimensional arrays completely unless you do the conversation yourself or have arrays of arrays.
|
# ? Nov 30, 2015 07:58 |
|
Have you seen Repa though? It's my understanding that it's based off of fortan's arrays and does allow efficient sectioning
|
# ? Nov 30, 2015 08:07 |
|
gonadic io posted:Last I checked, Data.Vector makes your index be an int and so disallows N-dimensional arrays completely unless you do the conversation yourself or have arrays of arrays. Yes, so it's like C. It's efficient, but not terribly expressive. gonadic io posted:Have you seen Repa though? It's my understanding that it's based off of fortan's arrays and does allow efficient sectioning Yeah, Repa is better, but it's very notationally and conceptually heavyweight (it really pushes the type system), so still not nearly as nice as arrays in true array languages. For example, if you have a two-dimensional array of integers, you should be able to map a function that takes a single-dimensional array and produces an integer, and end up with a single-dimensional array (just like you can do with a list or array-of-arrays). This is not terribly nice to express in Repa.
|
# ? Nov 30, 2015 11:32 |
|
Yeah, when I used Repa for image processing (calculating stereoscopic depth from two images taken side by side) a few years ago I really struggled with using Repa.
|
# ? Nov 30, 2015 11:36 |
|
I had an interview today for a devops job that requires python and they asked me how I'd flip the keys and values in a dictionary and I came back with code:
and it seemed to throw them a bit and they asked if I knew another way so I did code:
which also seemed awkward? can I chalk it up to writing code on a whiteboard is weird or did I miss some standard interview fizz buzz thing
|
# ? Nov 30, 2015 14:20 |
|
ahmeni posted:I had an interview today for a devops job that requires python and they asked me how I'd flip the keys and values in a dictionary and I came back with what happens if two keys map to the same value
|
# ? Nov 30, 2015 14:26 |
|
ahmeni posted:I had an interview today for a devops job that requires python and they asked me how I'd flip the keys and values in a dictionary and I came back with eh, i'd assume they expected a loop or such, and you just went more idiomatic than they saw coming, unless this is some very highly skilled job
|
# ? Nov 30, 2015 14:27 |
|
MALE SHOEGAZE posted:
this would be true if the people who were replacing their bash scripts wrote them in ruby, instead of writing template bash scripts and filling them in with values from a yaml config file.
|
# ? Nov 30, 2015 14:55 |
|
ahmeni posted:I had an interview today for a devops job that requires python and they asked me how I'd flip the keys and values in a dictionary and I came back with these both seem fine answers, the first more than the second. often when they ask you to repeat things they're asking you to give the answer in front of them that may or may not be related to the question at hand.
|
# ? Nov 30, 2015 14:57 |
|
Huh, so if a dictionary has duplicate values in it, values() will contain duplicates? Knowing that is going to save me a few puzzled hours one day.
|
# ? Nov 30, 2015 16:20 |
|
not sure what it would otherwise do, duplicate values should certainly be allowed, so stuffing them in a set would be pretty broken
|
# ? Nov 30, 2015 16:25 |
|
So is the right answer some sort of dumb (in the complexity sense) foreach loop that turns duplicate keys into some type of list of values to deal with key collisions? Kinda like you would do with a hashtable?
|
# ? Nov 30, 2015 16:44 |
|
If you wanted no loss of information whatsoever, I'd use the old values as new keys, but then the old keys would be stored as lists of values. I haven't pythoned in like 4-5 years so bear with me Python code:
Python code:
MononcQc fucked around with this message at 16:57 on Nov 30, 2015 |
# ? Nov 30, 2015 16:53 |
|
that's what i figured. holy cow is python's syntax for that so much cleaner than what i'd do in a c-family language. it's too bad i've never found a good reason to learn python around here.
|
# ? Nov 30, 2015 17:15 |
|
MononcQc posted:If you wanted no loss of information whatsoever, I'd use the old values as new keys, but then the old keys would be stored as lists of values. collections.defaultdict(list) maybe
|
# ? Nov 30, 2015 17:15 |
|
really don't understand why python doesn't have built-ins for really common things like reversing hashes, flattening lists, etc.
|
# ? Nov 30, 2015 17:34 |
|
LeftistMuslimObama posted:that's what i figured. holy cow is python's syntax for that so much cleaner than what i'd do in a c-family language. it's too bad i've never found a good reason to learn python around here. pfft, python is so wordy, the k solution is far more elegant (e.g. for d:`a`b`c`d`e!1 2 1 1 2 the result is 1 2!(`a`c`d;`b`e)): code:
(actually the map/last-builder syntax of python and others is one of those syntactic conveniences which is right up there with pattern matching in how surprisingly helpful and comprehensible it is; there is a reason why nerd favorites tend to have both)
|
# ? Nov 30, 2015 17:37 |
|
code:
|
# ? Nov 30, 2015 17:46 |
|
lol throw the loop macro in the trash where it belongs
|
# ? Nov 30, 2015 18:53 |
|
the loop macro is what soured me, for better or worse, off of common lisp. it seemed to be the best way to do iterative things in common lisp, but its it's own weird non lispy dsl. when i write lisp i want to write lisp
|
# ? Nov 30, 2015 18:56 |
|
dict:fold(fun(K,V,D) -> dict:append(V,K,D) end, dict:new(), Dict) vv
|
# ? Nov 30, 2015 18:58 |
|
clojure has it built in apparently and its basically the same impl as ^^code:
|
# ? Nov 30, 2015 18:59 |
|
MALE SHOEGAZE posted:really don't understand why python doesn't have built-ins for really common things like reversing hashes, flattening lists, etc. are these things really all that common? i mean that's not an argument against having a built-in, given that it does come with implementations of other not-particularly-common things, and it's dumb when they actively refuse to add that kind of thing because "it's only a one-liner to implement it yourself", but you can see how they'd slip through the net
|
# ? Nov 30, 2015 19:01 |
|
okay, now someone do the map flip thing with brainfuck
|
# ? Nov 30, 2015 19:08 |
|
MononcQc posted:If you wanted no loss of information whatsoever, I'd use the old values as new keys, but then the old keys would be stored as lists of values. yeah this is correct or at least more correct inverting a finite dict only works if the dict represents an injective function e: and defaultdict (of lists) encapsulates the check if exists logic
|
# ? Nov 30, 2015 19:12 |
|
MALE SHOEGAZE posted:really don't understand why python doesn't have built-ins for really common things like reversing hashes, flattening lists, etc. there's a lot of dumb tricks in the itertools documentation
|
# ? Nov 30, 2015 19:14 |
|
Barnyard Protein posted:the loop macro is what soured me, for better or worse, off of common lisp. it seemed to be the best way to do iterative things in common lisp, but its it's own weird non lispy dsl. when i write lisp i want to write lisp format owns too
|
# ? Nov 30, 2015 19:31 |
|
weird posted:format owns too yeah format gets a pass with me because i can understand how to use it
|
# ? Nov 30, 2015 19:55 |
|
Soricidus posted:are these things really all that common? i don't really reverse hashes that much, and when I do I usually want to handle collisions on my own. If flattening a list is not a common thing, then I'm programming wrong. Anyhow, these were just two examples, there are tons of other things that python really seems to be lacking to me. I don't have a list though, because I don't write python that much. I just know that I'm frequently copy + pasting basic things from stack overflow.
|
# ? Nov 30, 2015 19:59 |
|
Here's a (sort of) map inversion in MUMPS, where the original map was a single-layer tree with subscript=key and the value of the subscript=value:code:
code:
|
# ? Nov 30, 2015 20:05 |
|
Cybernetic Vermin posted:oK from a few pages back depress me by seemingly not allowing indexing an array with a dictionary, though it may be some K5 change which i am unaware of It's a K5 limitation, I'm afraid. Many things have been aggressively simplified compared to K4. There's still a reasonably simple K5 formulation. No repeat values: code:
code:
|
# ? Nov 30, 2015 20:44 |
Python really should have a deep_flatten() somewhere (probably in itertools) because of the pitfalls with strings.
|
|
# ? Nov 30, 2015 21:38 |
|
In Perl it'sPerl code:
|
# ? Nov 30, 2015 21:44 |
|
thanks for the feedback folks, apparently I did well and am through tithe next round of garbage: an "aptitude test" and some on-site pairing with people to do some technical work? the first I've done before and they're terrible, the second sounds neat but weird
|
# ? Nov 30, 2015 21:52 |
|
ahmeni posted:thanks for the feedback folks, apparently I did well and am through tithe next round of garbage: an "aptitude test" and some on-site pairing with people to do some technical work? the first I've done before and they're terrible, the second sounds neat but weird aptitude install job-ng
|
# ? Nov 30, 2015 21:56 |
|
|
# ? May 22, 2024 09:40 |
|
ahmeni posted:thanks for the feedback folks, apparently I did well and am through tithe next round of garbage: an "aptitude test" and some on-site pairing with people to do some technical work? the first I've done before and they're terrible, the second sounds neat but weird What kind of aptitude test? Like "are you skilled enough" tests or "what's your personality type" tests? both are terrible but for various reasons. Pairing is time-consuming, but I don't hate it. lt lets you have a look at who you'll work with and how they are. You're interviewing them as much as they interview you in there, so try to avoid stuff like "let me show them how great I am" and try to make it more like your everyday work interaction with them. Otherwise they'll be observing you, but you won't be getting your part back.
|
# ? Nov 30, 2015 22:45 |