r/badcode • u/kurtknispel_ • Jun 05 '22
python trying to change one element in n dimensional dictionary w/o knowing the number of dimensions 💀
739
Upvotes
r/badcode • u/kurtknispel_ • Jun 05 '22
319
u/erosPhoenix Jun 06 '22
94
u/Encursed1 Jun 06 '22
I feel like that's a data structure issue at that point
21
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jun 06 '22
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
34
u/dimonoid123 Jun 06 '22
Why would you do this?
Also, keys instead of keys[0] might be a bug, since it is a list.
6
u/sonya_numo Jun 06 '22
50% of the senior assesments i send out with recursiveness come back like this.
Come on man, its at best a 3 or 4 hours to write the simple reusable function with time to add fun features and a little refactor.
7
u/trutheality Jun 06 '22
One of those cases where recursion is a better friend than iteration.
3
u/bkucenski Jun 06 '22
Solving problems created by problems with new problems.
8
u/QuarkUpParticle Jun 06 '22
1
u/[deleted] Jun 07 '22 edited Jun 07 '22
If this is a NumPy array, then it's simply:
values[tuple(keys)] = value, assumingkeysisn't already atuple.Also, amazing how many readers contributed more bad solutions to this problem...
1
u/[deleted] Sep 29 '22
next major update: added support up to 6 elements in array
1
u/Old-Yogurtcloset-629 Jan 04 '23
well i mean in python its pretty easy, due to mutability of lists. But how do you do this in other languages like java?