[Tutor] Replace nth item with single value in each nested list

EK Esawi ekesawi at yahoo.com
Thu May 14 10:28:08 EDT 2020


Hi all--


Thank you Mats for the help.

On my previous post, I did not state my question accurately. The question is how do I replace the 2nd element in each sublist based on a condition? For example, replace the 2nd element with 11 in each sublist if it’s greater than 5. If a=[[1,2],[4,5],[7,8],[3,6]] then the desired results would be  a=[[1,2],[4,5],[7,11],[3,11]]. if possible via list comprehension

Thanks again--EK.
 


More information about the Tutor mailing list