Select the first element from the first list, the second element from the second list, and so on, in a nested list

Let’s say I have a list like this: lst <- list(list(1,2,3),list(4,5,6),list(7,8,9)) I would then like to extract the elements 1, 5, and 9. How should I do that in an efficient manner? I’ve come across this post; Select first element of nested list, where it is suggested that one should use: lapply(x, ‘[[‘, 1) to… Read More Select the first element from the first list, the second element from the second list, and so on, in a nested list

How to remove space between expression and period within a string? (Python 3)

Good Morning, I’ve been trying to get rid of the space between the period and the number generated from sum(random_list) output [23739]. But can’t seem to figure out how without turning the entire string to an f-string. I understand adding the comma will automatically insert a space, but can anyone let me know if there’s… Read More How to remove space between expression and period within a string? (Python 3)

more concise way to make this?

I’m unsure of how to create a certain section of my code without it being excessively long and tedious. Is there perhaps a way of utilizing a range function where I need my elif statements? Any help shortening this would be more than appreciated! #just some sample lists Player.PlayerList[1].carrier_row = [0,1,2,3,4] Player.PlayerList[1].carrier_col = [5,5,5,5,5] Player.PlayerList[1].battleship_row… Read More more concise way to make this?

Generating multiple csv from a list

Using the markovchain library, I managed to generate 144 transitions probability matrixes (eg. matrixList), but how can I save all (143) as a .csv file? library(tidyverse) library(markovchain) mcListFist<-markovchainListFit(data=df[, 1:144], name="df") matrixList<-list() for (i in 1:dim(mcListFist$estimate)) { myMatr<- mcListFist$estimate[[i]]@transitionMatrix matrixList[[i]]<-myMatr } matrixList Output of transition probability matrix 84-85 ………… [[84]] 0 0 1 [[85]] 0 0… Read More Generating multiple csv from a list