Why is print not printing my array sorted

This is my original array: a = [0, 4, 7, 8, 1, 3, 5, 2, 6] and this is what it prints: [0, 4, 7, 0, 0, 0, 5, 0, 0] Answer As @’Lee Jun Wei’ it doesn’t look like your algo is right. But there may be a few other things to point out. These two lines look off. i and j are taking on the value of the elements of a not the index values. I think you mean The reason you get zeros is because min is initialized to 0. Note that it is zero not because

Buttons in a for loop to update labels in a for loop?

Trying to get individual buttons to update individual labels in tkinter. Here’s my code: When you run the code there are three buttons in a column next to three labels in the next column over. What I’m trying to do is get it so that each button changes the label next to it. What happens when I run the code is every button modifies the last label and the other two labels are untouched. Any help is awesome, thanks! Answer This will work for you. I don’t think you understand how the buttons work. Once you .grid() them they are

Python dynamic for loop range size

I’m trying to add Link argument to ini file by using python. Example of ini file: I need to do like this: My for loop: My code works, but it does not add Link for last tags. I’ve found why. If I add in range(len(m)+100): Then code adds all Links. Looks like len(m) is old value (static?), because I’m increasing len with insert during loop. Any ideas? I have tried something like insertings = 0, then range(len(m)+insertings) and afer insert insertings = insertings+1 But no luck :( Answer Create a new list:

Why does it ignore my continue in the for-loop? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 7 months ago. Improve this question Hello I’m new here and would like to know, why my for-loop doesn’t react to the continue. It goes into the else branch. But just ignores the continue. Answer I suspect you have it backwards: continue is being executed when it shouldn’t be. You need to use elif for your sequence of conditions. Your else: block is only associated with the last

How do you eliminate items from nested lists

Given a list of ranked ballots and a list of candidates to eliminate, I need to return a new list of ranked ballots where all the candidates in the list of candidates to eliminate have been removed. This is the code I’ve tried so far My first doctest is failing, giving me this output instead: Answer This is the function required. It searches through the sublists: Output:

Web scraping problem during passing fuction as paramater in function

Hello I’ve created two functions that work well well called alone. But when I try to use a for loop with these functions I got a problem with my parameter. First function to search and get link to pass to the second one. Second function to scrap a link. All these function worked when I tested them on a link. Now I have a csv file with name of companies using searchsport() to search in website and the returned link is passed to single_text() to scrape. Error: When I run this I got a df. My expected results should be

For loop is taking only the last element in the list

I am sorry for a simple question, but tried multiple options without any solution. he Problem I have is the for loop is taking only the last value in the list(Regions). This is the list and it takes only the last value It has to take all the values in the list(Regions) and display the result. But it takes only the last value(us-east-1). Please advice what is causing the error. Answer Here: you are creating a new csv file for each region, overwriting the previous one. You want to keep this out of the loop:

how to scrape all items of a page using a loop

i’m trying to scrape and list 24 items from a certain website. instead, it shows the same item 24 times. to get the first price i did this: as said, it does print 24 lines. but instead of listing all the different ones, it just lists the first result (probably because the i = 0). i’m very bad at coding so I don’t know what to change to get the wanted result. any thoughts? Answer Try the below code. Output:

Python for and if on one line

I have a issue with python. I make a simple list: I want create a “single line code” for find a string. for example, I have this code: But when I watch the variable is wrong (I find the last value of my list): Why does my variable contain the last element and not the element that I want to find? Answer You are producing a filtered list by using a list comprehension. i is still being bound to each and every element of that list, and the last element is still ‘three’, even if it was subsequently filtered out