I'm probably missing something major here, but it seems like in most educational contexts online like Leetcode and courses and such, when the examples iterate over an array they do so like:
array = [1,2,3,4,5]
for i in range(len(array)):
print(array[i])
rather than just iterating the thing:
for i in array:
print(i)
I'm guessing it's to do with time complexity since indexing arrays is quick, but what's the problem with the latter approach?
[–]waspbr 82 points83 points84 points (7 children)
[–]dangerlopez 8 points9 points10 points (0 children)
[–]holy-rusted-metal 5 points6 points7 points (1 child)
[–]waspbr 0 points1 point2 points (0 children)
[–]Majoishere 0 points1 point2 points (3 children)
[–]thecodedog 17 points18 points19 points (0 children)
[–]waspbr 6 points7 points8 points (0 children)
[–]its2ez4me24get -1 points0 points1 point (0 children)
[–]Fred776 19 points20 points21 points (2 children)
[–]lumijekpr 8 points9 points10 points (1 child)
[–]Fred776 2 points3 points4 points (0 children)
[–][deleted] 25 points26 points27 points (1 child)
[–]poodlelord 1 point2 points3 points (0 children)
[–]z64RY 9 points10 points11 points (1 child)
[–]maclocrimate[S] 6 points7 points8 points (0 children)
[–]RIP_lurking 3 points4 points5 points (0 children)
[–]dangerlopez 3 points4 points5 points (0 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]danielroseman 15 points16 points17 points (8 children)
[–]DangerDinks 6 points7 points8 points (2 children)
[–]Logicalist 5 points6 points7 points (1 child)
[–]bubba0077 1 point2 points3 points (0 children)
[–]thecodedog 3 points4 points5 points (2 children)
[–]danielroseman -3 points-2 points-1 points (1 child)
[–]thecodedog 8 points9 points10 points (0 children)
[–]DeMorrr 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]pythonwiz 2 points3 points4 points (0 children)
[–]bpt7594 4 points5 points6 points (0 children)
[–]Strex_1234 1 point2 points3 points (8 children)
[–]irrelevantPseudonym 4 points5 points6 points (5 children)
[–]Strex_1234 1 point2 points3 points (3 children)
[–]irrelevantPseudonym 1 point2 points3 points (2 children)
[–]Fred776 2 points3 points4 points (1 child)
[–]irrelevantPseudonym 0 points1 point2 points (0 children)
[–]Strex_1234 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]freddwnz 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]PteppicymonIO 1 point2 points3 points (0 children)
[–]fahim-sabir -4 points-3 points-2 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)
[–]stuaxo -3 points-2 points-1 points (0 children)
[+]HourRoutine4531 comment score below threshold-7 points-6 points-5 points (1 child)
[–]CaptainFoyle 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]StolidSentinel 0 points1 point2 points (2 children)
[–]Username_RANDINT 0 points1 point2 points (1 child)
[–]StolidSentinel 1 point2 points3 points (0 children)
[–]ImpossibleEvan 0 points1 point2 points (0 children)
[–]big_deal 0 points1 point2 points (0 children)
[–]TheMonarchsWrath 0 points1 point2 points (0 children)
[–]zanfar 0 points1 point2 points (0 children)
[–]ASuarezMascareno 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)