Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Activity for NoahTheDuke
Type | On... | Excerpt | Status | Date |
---|---|---|---|---|
Comment | Post #284926 |
I see now that my solution was already proposed by @hkotsubo, tho in a slightly roundabout way. I am still certain that it is a faster method than the nested loop with `divmod`. (more) |
— | about 3 years ago |
Edit | Post #284926 | Initial revision | — | about 3 years ago |
Answer | — |
A: Python looping 300 000 rows I’m struggling to get `timeit` working correctly but this is faster in my limited tests: ```python l = [123456789, 23456789012, 34567890123] result = [0, 0, 0] for idx, row in enumerate(l): i = f"{row:011}" result[idx] = f"{i[:2]}-{i[2:4]}-{i[4:5]}-{i[5:8]}-{i[8:]}" print(result)... (more) |
— | about 3 years ago |
Edit | Post #284900 | Initial revision | — | about 3 years ago |
Answer | — |
A: Add single element for multiple keys to map `(apply assoc m1 (interleave ks (repeat itm)))` Demonstration: ```clojure $ clj Clojure 1.10.3 user=> (def m1 {:a 1 :b 2}) #'user/m1 user=> (def itm 3) #'user/itm user=> (def ks [:c :d :e]) #'user/ks user=> (apply assoc m1 (interleave ks (repeat itm))) {:a 1, :b 2, :c 3, :d 3, :e 3} ``... (more) |
— | about 3 years ago |
Edit | Post #284899 |
Post edited: Add clj command and Clojure version to repl output |
— | about 3 years ago |
Edit | Post #284899 | Initial revision | — | about 3 years ago |
Answer | — |
A: Add single element for multiple keys to map `(merge m1 (zipmap ks (repeat itm)))` Demonstration: ```clojure $ clj Clojure 1.10.3 user=> (def m1 {:a 1 :b 2}) #'user/m1 user=> (def itm 3) #'user/itm user=> (def ks [:c :d :e]) #'user/ks user=> (merge m1 (zipmap ks (repeat itm))) {:a 1, :b 2, :c 3, :d 3, :e 3} ``` `repeat` retur... (more) |
— | about 3 years ago |
Edit | Post #284898 | Initial revision | — | about 3 years ago |
Question | — |
Add single element for multiple keys to map I have a map and a new item to add to the map and a list of keys I want to attach the new item to: ```clojure => m1 {:a 1 :b 2} => itm 3 => ks [:c :d :e] => m2 {:a 1 :b 2 :c 3 :d 3 :e 3} ``` I thought of using `reduce`, but that seems overly wordy. How best do I do this? (more) |
— | about 3 years ago |