How to move all items one item forward in a list

I’m trying to do the following (consider this list): [‘Hello, ‘Hi’, ‘Nice’, Cool’] I would like to change ‘Hi’ to ‘Love’ But, I wouldn’t want it to stay that way: [‘Hello, ‘Love’, ‘Nice’, Cool’] I’m trying to get ahead of the others, even cropping the last one, getting like this: [‘Hello, ‘Love’, ‘Hi’, Nice’] Note… Read More How to move all items one item forward in a list

Remove elements from a list based on a condition in Python, problem: loop removes only the first instance

For each element in my list I’d like to check: if it includes ‘strategies available for player’, or is it equal to ‘\n’ If yes, the element should be removed. I’ve written a loop to iterate over the list. It removes the first instance of ‘strategies availbale for player’ just fine but totally ignores the… Read More Remove elements from a list based on a condition in Python, problem: loop removes only the first instance

How to zfill after a certain value in a list

I have a list that looks like this ls = [‘DATA2022_10.csv’, ‘DATA2022_2.csv’, ‘DATA2022_3.csv’, ‘DATA2022_4.csv’, ‘DATA2022_5.csv’, ‘DATA2022_6.csv’, ‘DATA2022_7.csv’, ‘DATA2022_8.csv’, ‘DATA2022_9.csv’] I want to zfill element in this list in order to sort my data. Expected output: ls = [‘DATA2022_02.csv’, ‘DATA2022_03.csv’, ‘DATA2022_04.csv’, ‘DATA2022_05.csv’, ‘DATA2022_06.csv’, ‘DATA2022_07.csv’, ‘DATA2022_08.csv’, ‘DATA2022_09.csv’, ‘DATA2022_10.csv’] zfill only allows me to add 0 on the… Read More How to zfill after a certain value in a list

Updating values inside a python list

ItemList = [ {‘name’: ‘item’, ‘item_code’: ‘473’, ‘price’: 0}, {‘name’: ‘item’, ‘item_code’: ‘510’, ‘price’: 0}, {‘name’: ‘item’, ‘item_code’: ‘384’, ‘price’: 0}, ] data_1 = ‘510’ data_2 = 200 def update_item(data_1, data_2): for a in ItemList: if a[‘item_code’] == data_1: update_price = append(a[‘price’].data_2) return True I want to update the price by using the function update_item.… Read More Updating values inside a python list

Repeat triple nested lists based on length of matching column in R

I would like to duplicate/repeat triple nested lists based on the number of rows matching the same name in a data frame. Here is a triple nested list: list.A <- list(a = c(1,2,5,6), b = c(2,4,6,5), c = c(2,4,2,5)) list.B <- list(a = c(7,7,7,7), b = c(8,8,8,8), c = c(9,9,9,9)) weights <- list(list.A, list.B) names(weights)… Read More Repeat triple nested lists based on length of matching column in R