I am working on a load function that loads files containing one pandas dataframe per file (or even better one np array). I.e. I am loading a .csv file and I want to link it to only one array variable. This function takes as input one dictionary containing the name I want (as key) the variable to take and the
Tag: data-structures
Sort List with duplicates based on related list
Shortened the scenario for brevity. I have three arrays where there is a relationship between the elements at i-th position between the three arrays.. for eg A1[0] is related to A2[0] and also A3[0] and so on … I want to sort the three arrays BASED ON THE A2 (in ascending order). so after sorting, the a…
How to take the item from string and use it as a value
I have a string and I need to use this string to fit a model. However when I try try to do this, of course it raises an error which can be seen below. How can I use this string to fit the model? Answer You need to evaluate the string into a Python object, ie do See documentation of
Python datastructure for keys being mapped to auto-increment integer value
I want to store a list of strings into a dictonary data structure, where the key will be the string I provided, and the value will be an auto-increment count. I could do this by keeping a manual counter and then using that when inserting values in a dictionary, but I wanted to know if there is any default dat…
Comparing two text files and the matches go to a new file
In python I would like to find a way to compare two text files and read one line by line and find it’s match if any in the other file. If they match I would like to take that string and write it to a new file. I do not know how I would even start this the only thing
Find root to leaf path with given sum. Code succeeds with string, fails with list
I am looking at a binary tree problem. The goal is to find all path(s) from root to leaf, such that the values on the path sum up to a given k. For that purpose I have written the same algorithm in two different ways: The first version uses a string parameter a. The second version uses a list parameter
Build tree/linked list from a list of Objects
I am trying to build a tree like hierarchy from modules and their respective submodules, each module has a name, data, and a list of its submodules, With this code I’m able to detect if something is a submodule of something else but I don’t know how I am supposed to form the connections/build the …
Time limit exceeded when finding tree height
this is my code to find the height of a tree of up to 10^5 nodes. May I know why I get the following error? Warning, long feedback: only the beginning and the end of the feedback message is shown, and the middle was replaced by ” … “. Failed case #18/24: time limit exceeded Input: 100000 You…
Python priority queue- subsequent pops return wrong values after first pop?
I am trying to solve Leetcode #347 Top K Frequent elements using a priority queue. However, my code is failing some test cases. Here is the code: Here is stdout when running this with k = 2 and nums = [4,1,-1,2,-1,2,3] Why does my code seem to skip over 2 as the the entry to return on the second call
Efficiently search a long list of lists
I have a long list of hexahedral point coordinates, for example: Each row defines a hexahedron cell, and by iterating over each cell, I extract the defining faces of the cell (6 faces), and add each face to a list processed_faces All of this is fine, but because some cells are sharing the same face, I needed …