Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I make every member in python array starts with zero?

How can I count down each member in ass until zero. Basically, every member should start with zero.

ass = [[8, 9],[0, 1, 2, 3],[3, 4, 5, 6, 7],[2, 3, 4, 9]]

For example; [8, 9] should be [0,1,2,3,4,5,6,7,8,9]
But [0, 1, 2, 3] now starts from zero, I do not change anything

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thank you

>Solution :

Combining range with remaining slice:

arr = [[8, 9],[0, 1, 2, 3],[3, 4, 5, 6, 7],[2, 3, 4, 9]]
arr = [list(range(0, a[0]+1)) + a[1:] for a in arr]

[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
 [0, 1, 2, 3],
 [0, 1, 2, 3, 4, 5, 6, 7],
 [0, 1, 2, 3, 4, 9]]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading