In the last part of the above titled video why we have iterated list with FOR loop to read the list of numbers??
Sorting and searching on lists
Hey shreya,
I think you are talking about this code numbers = [int(no) for no in input().split()]
This is list comprehension technique, So what we wanted to do is take input integers as many as user wants.
But input()
returns a string value.
“1 2 3 4 5” Like this. now we can split this string using space then it would become [“1”, “2”, “3”, “4”, “5”]
But numbers are still in string form not integers.
So, we iterated over list list and converted all strings to int.
I hope this clears your doubt.
Thanks
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.