Im trying to make a function which finds a value from a list (xs) using another list (index_list) as an index path. My function should work like this: So far I have: This however just returns 0 for everything, but I don’t know what else the base case should be. Answer You’re quite close, but you f…
Tag: python
Replacing character in string doesn’t do anything
I have a list like this, Expected output: Removing the brackets is easy by using .replace(), but I don’t want to remove the brackets from strings (#) and (##). my code: but this doesn’t remove the brackets from the words. Answer You can use re.sub. In particular, note that it can take a function a…
How to import API data using Pandas?
I am trying to pull some data from EIA API, below is what I tried but I’m getting the error on the first line of code: AttributeError: ‘str’ object has no attribute ‘text’ Any help would be much appreciated! Answer You haven’t requested anything from the API. Look carefully…
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
Django Rendering Form in HTML Issue
I’m attempting to render a form, in html and have tried the normal {{ form }}. However when I go to the site set up by: python manage.py runserver. I get the following where the form should go (highlighted section on screen-capture) webpage This is the code for the form in question. forms.py This is the…
Creating a word length frequency table in python
I have the following code: Without importing anything else, how would I make a table which prints the length and then the frequency. For example: In a file with the text of “a blah ba ba” it would print: What confuses me about this is how to add all the length of the words together, should I be ma…
django FieldError: Cannot resolve keyword ‘category_name_contains’ into field. Choices are: category, description, id, image, name, order, price
I want to build a food delivering app, but facing this error. “FieldError: Cannot resolve keyword ‘category_name_contains’ into field. Choices are: catego ry, description, id, image, name, order, price”. This is the query.py: This is the views.py This is my models.py: Here’s the …
page of FLASK app is not changing after uploading a file, progress bar works fine
I want to perform some analysis on a text file. Once file is uploaded in the webpage, I am trying to redirect the route, But that isn’t working. Surprisingly, print statement is running in the console of the redirected route, but the template isn’t rendering. Debug mode is true, I have multiple ti…
Iterating over 2 lists in SQL execution using SQL Alchemy
I currently have this query: That I changed to use bindparams: So before, I was able to make the query per table in the bmds_stage_table list and change_set_ids was just 1 int But now change_set_ids is a list of ints. So now, for each change_set_id I want to iterate through all the tables in the bmds_stage_ta…
Best way of getting Qt pushbuttons Icons information in python?
Im developing a PyQt application which modifies buttons icons dynamically. The icons are created with QStyle, stored as class parameters and then put into the buttons with the setIcon() method. Since the icons are modified dynamically, i want an elegant way of checking what is the current button icon. The ori…