I have a list that can be of any depth or length. By this I mean I could have a list like so:
lst = [1,2,3]
Or:
lst = [[2,233],[[[4,5],[66.33]],[[24,88.65,103,2200.0],[-44.2,-8,5]]], [[[[[[[[5]]]]]]]]]
and what I would like to do is randomly modify a single one of any of these numerical values in the list. I'm aware I could do something dodgy by converting the list to a string, but if there is a standard way of doing this, an answer pertaining to such would be appreciated!
Edit:
For those unaware, you cannot simply randomly select any of these values and modify it (as an example, say, add 1 to it), as the list could be nested. Here is an example of the input and output I am trying to get:
lst = [[2,233],[[[4,5],[66.33]],[[24,88.65,103,2200.0],[-44.2,-8,5]]], [[[[[[[[5]]]]]]]]]
lst = modify(lst,4) # Where 4 is the amount to add to a random number in the list
>lst: [[2,233],[[[4,9],[66.33]],[[24,88.65,103,2200.0],[-44.2,-8,5]]], [[[[[[[[5]]]]]]]]]
# the fourth number to appear left-to-right in the list 5 has had 4 added to it, ultimately resulting in 9
# this number was randomly selected
Running the same code again, with the lst
now updated:
lst = modify(lst,-2)
>lst: [[2,233],[[[4,9],[66.33]],[[24,86.65,103,2200.0],[-44.2,-8,5]]], [[[[[[[[5]]]]]]]]]
# The seventh number 88.65 has had 2 subtracted from it, to ultimately equal 86.65