range

create tuple from ranges in python

create tuple from ranges in python Question: Is there a way in python to create a tuple of months and years (as: [(2020, 1),(2020,2)…] ) by using the tuple() function? My code: monthyears = [] for y in range(2020,2017,-1): if y == 2018: m_end = 6 else: m_end = 0 for m in range(12,m_end,-1): monthyears.append((y,m)) …

Total answers: 3

Out of range .csv py

Out of range .csv py Question: I am trying to extract values from .csv file the problem is i getting an error out of range when using a file with over 6000 data, however when using file with about 200 There is such an error import csv # Read the csv file and store the …

Total answers: 1

Generating number Sequence Python

Generating number Sequence Python Question: I want to generate a number sequence that repeats 2 consective numbers twice then skips a number and repeats the sequence wihin the range specified. such as 0,0,1,1,3,3,4,4,6,6,7,7 and so forth. what I have so far numrange = 10 numsequence = [i for i in range(numrange) for _ in range(2)] …

Total answers: 2

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

Reversing a 2d grid so (0,0) is on the bottom left, instead of top left

Reversing a 2d grid so (0,0) is on the bottom left, instead of top left Question: I have a 2d grid, where 0,0 is the top left corner of the grid. However, I need 0,0 to be the bottom left corner with the y axis increasing bottom to top. for x in range(engine.map_size): for y …

Total answers: 2

Check if item exists in same position in each nested list – Python

Check if item exists in same position in each nested list – Python Question: I’m writing a Connect Four script. The script takes a list of moves as input ("A_Red, "B_Yellow", "G_Red", etc), which I’m sorting into a matrix. Each nested list represents a column of the board with "A" being the first nested list …

Total answers: 1

Create a new DataFrame using pandas date_range

Create a new DataFrame using pandas date_range Question: I have the following DataFrame: date_start date_end 0 2023-01-01 16:00:00 2023-01-01 17:00:00 1 2023-01-02 16:00:00 2023-01-02 17:00:00 2 2023-01-03 16:00:00 2023-01-03 17:00:00 3 2023-01-04 17:00:00 2023-01-04 19:00:00 4 NaN NaN and I want to create a new DataFrame which will contain values starting from the date_start and …

Total answers: 2

Unexpected outcome with the range function, slightly confused

Unexpected outcome with the range function, slightly confused Question: I am new to Python, so apologies if this seems silly. But, I’m trying to remove certain indices from a list with a for loop and the range function, but rather than the range being incremented by one, it’s going up by 2, even though I …

Total answers: 2

Python list to range

Python list to range Question: I have the list lst = [3, 5] How to get a range for each item in the list like this ? [0, 1, 2, 3] [0, 1, 2, 3, 4, 5] This is loop is obviously not working for i in range(0, lst): print(i) Asked By: hug || Source …

Total answers: 2

Range in For-loop Python

Range in For-loop Python Question: for i in range(4,7): i=i+3 print("Hello") Kindly help me with the well explained output for this program. Asked By: Rahul.S || Source Answers: This code uses a for loop to iterate over the numbers in the range 4 to 7 (inclusive). For each number i in the loop, it adds …

Total answers: 2