Skip to content

Tag: python

Find match of numeric arrays Python

Consider I have 2 arrays. arr2 will always be longer than arr1. I’d like to drop the values from arr2 to best fit arr1. If arr2 doesn’t have an equal value to arr1 it will need to be the closest value that is still in arr2. observing the output. the first value is 0, both have a match at the

reassign global boolean from a function

i am trying to reassign the value of these booleans from inside of a function and use the reassigned values inside of another function. how do i do that? Answer In general, you should avoid trying to do this, as it can make your code harder to understand and debug (see action at a distance). But, if you&#8217…

How to convert a char array to a number for sorting?

Let’s say I have three words I want to sort: hello goodbye alex And alphabetically it’d be sorted ascendingly as [“alex”, “goodbye”, “hello”]. Is there a way to convert the string (limited to 100 characters)? For example, if I have: And I use ord to get the code…

Dynamically changing a list while looping

I have a list: what I would like to do is loop though this list but then change the list. Basically when I loop through nums = [0, 1, 2, 3] nums would need to change to: Is there a way of changing nums like this? I feel like there is a simple solution to this, but I’ve been stumped