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

Find the value in the middle of the list

Greeting everyone! I need help, i have the list with an odd numbers of elements, and i have to find the value placed in the middle of the list. I understand it`s not big deal but my brain is decided to shut down

>Solution :

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

you first get the length of your list "len(listName)" you can store it in a new variable. The element in the middle of the list is the element at the index length // 2 because the first element of the list have an index of 0
so the element will be:
array[len(array) // 2]

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