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
Tag: python
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’…
Python3 interpret user input string as raw bytes (e.g. x41 == “A”)
I want to accept user input from the command line using the input() function, and I am expecting that the user provides input like x41x42x43 to input “ABC”. The user MUST enter input in the byte format, they can not provide the alphanumeric equivalent. My issue is that when I take in user input, a…
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
I have written this function to get the size of a string, can it be optimized?
I don’t want to use python functions to calculate but I want to implement a function myself. The problem comes when the chain is very long. The program starts to take about 5 minutes. Answer Why don’t you use len()? I think what you’re trying to do is just len(‘holaaaaaa’) and I …
Format Changing Problem of Number Input in streamlit
The program offers the number format as Default in a.b format (like 1.2) but I want to show as a:b format (like 1:2) How can I change this? I tried below but it didn’t work: Answer
How to create dictionary from multiple dataframes?
I have a folder with several csv files. Example of the dataframes from csv files in directory: I need to make a function that accepts route to file directory and return sites frequency dictionary (one for all sites in file directory) with unique sites names the following kind: {‘site_string’: [sit…
How to update the title of an App in kivy by clicking a button
I’d like to change the title of the main App screen(AwesomeApp). The title of my App when it runs is “My house”. But i want to change it when I click “Update Top Bar’s name” inside “Information” popup window. When i click “Update Top Bar’s name”…
Assigning dict to class variable converts it to tuple
I’ve been using python for a while and I’ve never run into this. I am passing a dict to a class and assigning it to a class variable like so. If I print the type of rule_list prior to assigning it to self.rule_list I get <class ‘dict’>. Immedietly after assignment, I get <clas…