<\/a>#Mastery22<\/a> <\/span> <\/span><\/a>#TC1014<\/a> <\/span> <\/span>@PablO_CVi<\/span><\/a><\/p>\n The for<\/strong> statement iterates through a collection or iterable object or generator function.<\/p>\n The while<\/strong> statement simply loops until a condition is False.<\/p>\n It isn’t preference. It’s a question of what your data structures are.<\/p>\n Often, we represent the values we want to process as a Generally, however, we have a ready-made collection: a set, tuple, list, map or even a string is already an iterable collection, so we simply use a for<\/strong> loop.<\/p>\n In a few cases, we might want some functional-programming processing done for us, in which case we can apply that transformation as part of iteration. The <\/p>\n If you don’t have a tidy data structure to iterate through, or you don’t have a generator function that drives your processing, you must use while<\/strong>.<\/p>\n <\/p>\n <\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":" #Mastery22 #TC1014 &nbs… Continue reading range<\/code> (an actual list), or
xrange<\/code> (which generates the values). This gives us a data structure tailor-made for the for<\/strong> statement.<\/p>\n
sorted<\/code> and
enumerate<\/code> functions apply a transformation on an iterable that fits naturally with the for<\/strong> statement.<\/p>\n