enumerate

why these 2 sorting is opposite in order

why these 2 sorting is opposite in order Question: I am implementing bubble sort in Python and used range for indexing the array: """ program to implement bubble sort """ a = [9,1,5,3,7,4,2,6,8] for i in range(len(a)): for j in range(i+1, len(a)): if a[i] > a[j]: a[i], a[j] = a[j], a[i] print(a) I got the …

Total answers: 2

Number the values ​that are in the series of the dataframe

Number the values ​that are in the series of the dataframe Question: I have this dataframe 0 312229 12 {"from":[3,4],"to":[7,4],"color":2},{"from":[3… ["v","b","c","c","a","h","i","e","r","s","f","… "#ff0000","#00fe00","#0000ff","#d2ea9a","#407f… "place","cartable","gomme","bureau","bibliothè… 4 400606 12 {"from":[3,4],"to":[7,4],"color":2},{"from":[3… ["v","b","c","c","a","h","i","e","r","s","f","… "#ff0000","#00fe00","#0000ff","#d2ea9a","#407f… "place","cartable","gomme","bureau","bibliothè… 8 410051 12 {"from":[3,4],"to":[7,4],"color":2},{"from":[3… ["v","b","c","c","a","h","i","e","r","s","f","… "#ff0000","#00fe00","#0000ff","#d2ea9a","#407f… "place","cartable","gomme","bureau","bibliothè… … And I need to convert this dataframe column 0 ["v","b","c","c","a","h","i","e","r","s","f","… 4 ["v","b","c","c","a","h","i","e","r","s","f","… 8 ["v","b","c","c","a","h","i","e","r","s","f","… 12 ["v","b","c","c","a","h","i","e","r","s","f","… 16 …

Total answers: 1

Python – Why does enumerate() cause a later zip() to only pull from the last item in list?

Python – Why does enumerate() cause a later zip() to only pull from the last item in list? Question: Code: boylist = [‘Jim’, ‘James’, ‘Jack’, ‘John’, ‘Jason’] for i, boylist in enumerate(boylist): print(f’Index {i} is {boylist} in my list’) #boylist = [‘Jim’, ‘James’, ‘Jack’, ‘John’, ‘Jason’] girllist = [‘Emma’, ‘Clara’, ‘Susan’, ‘Jill’, ‘Lisa’] for boylist, …

Total answers: 2

subclassing the builtin enumerate in python

subclassing the builtin enumerate in python Question: Consider the code below. I am trying to subclass the builtin enumerate so that it prints a line for every turn of the for loop. The code seems to be working, which is surprising, because I have never called super().__init__(x). So, what is happening here? Who is initializing …

Total answers: 1

how i can calculate the adjacent and opposite of this matrix?

how i can calculate the adjacent and opposite of this matrix? Question: i have this matrix Matrix = [[0., 15., 19., 18., 17.], [15., 0., 14., 12., 23.], [19., 14., 0., 14., 21.], [18., 12., 14., 0., 14.], [17., 23., 21., 14., 0.]] and i cut it to this by this code c = [item[:index+1] …

Total answers: 1

try/except if/else – how to replace 'None' output

try/except if/else – how to replace 'None' output Question: I am trying to write a function that will take a target number, and a matrix as its parameter, and will return the ‘co-ordinates’ of the target number. If the target number doesn’t exist, (-1, -1) will be returned. It is assumed there will only be …

Total answers: 2

Creating a ranking in Python from a given value by id

Creating a ranking in Python from a given value by id Question: I have this dataset: dic = {‘id’:[1,1,1,1,1,2,2,2,2], ‘sales’: [100.00, 200.00, 300.00, 400.00, 500.00, 100.00, 200.00, 300.00, 400.00], ‘year_month’: [202201, 202202, 0, 202204, 202205, 202201, 202202, 202203, 0]} df = pd.DataFrame(dic) Output: id sales year_month 0 1 100.0 202201 1 1 200.0 202202 2 …

Total answers: 2

Why am I getting IndexError: list index out of range

Why am I getting IndexError: list index out of range Question: from openpyxl import load_workbook book = load_workbook(‘Line_Machines_Data.xlsx’) sheet = book[‘Line 7 machines’] line_7data = [15, 20, 30, 40] # this is the new data for row in sheet[‘A1’ : ‘F1’]: #iterates through each row for count, cell in enumerate(row): cell.value = line_7data[count] book.save(‘Line_Machines_Data.xlsx’) I …

Total answers: 1

How to join counts from enumerate() in python?

How to join counts from enumerate() in python? Question: How can I join double/triple/etc.-digit counts from enumerate() to form a single string? I want to iterate through a list of US 5-digit zipcodes in order that a new list is formed containing a reference url rewritten with each zipcode in the list: # "70048" is …

Total answers: 2