Skip to content

Tag: list

How to change one element in a sublist using list comprhension

I am worrying in python, and I’ve a list composed by 8 sublists, made in this way: [[value1,value2,value3], …]. I want to change to “False” only the third value (value3) in all sublists using a list comprhension, but my code does not work, and a I don’t know why. athlete_session_…

How can I count the depth in a list of lists?

I want to count the depth in a list of lists, so not the amount of elements but the maximum depth one list can have. This is my function: should return 4 Answer You can try: Output: Explanation: First check if object passed into the recursive function is of type list: If so, proceed to add up the Trues in

Convert dictionary containing fractions into string

I want to convert a dictionary into a list of strings. Although my actual code is much longer, a MWE is: The output is: If I try the fractions package, it seems I can convert fractions themselves into something suitable but it doesn’t work for dictionaries or arrays: I want to extract all the numerical …

How to store multiple strings in list in Python?

I have this ListOfCoordinates list with 5 tuples (image below), with each index corresponding to the coordinates of two regions of the brain. I also have this variable named brain_areas_ROIs, which is a dictionary (image below) with the names of all possible brain regions. So I want to store in a dictionary t…