https://365datascience.com/dwqa-answer/answer-for-printing-out-every-object-element-in-a-list/ -
Hi Min!
Thanks for reaching out!
It depends on what you are aiming to achieve.
If you are looking for a more organised and frequently encountered piece of code, perhaps you can opt for the second option.
But if you are trying to obtain the output quickly, it seems that the first option is the one to choose.
You can help yourself with the time module to measure the time it takes Python to deliver the output while executing the two code cells.
import time
start = time.time()
for a in m:
print (m[m.index(a)], end = " ")
end = time.time()
print(end - start)
and
start = time.time()
for k in range(len(m)):
print (m[k], end = " ")
end = time.time()
print(end - start)
Hope this helps.
Best,
Martin
#365datascience #DataScience #data #science #365datascience #BigData #tutorial #infographic #career #salary #education #howto #scientist #engineer #course #engineer #MachineLearning #machine #learning #certificate #udemy
No comments:
Post a Comment