Looping technique in PythonPython has specific inbuilt functions, due to which it supports numerous looping techniques in several sequential containers. These looping functions and methods are very useful for competitive coding. It can be used in different projects in which user has to use some specific technique with loops for maintaining the whole structure of the program. These techniques help save time and memory space as the user does not have to declare the extra variables for the traditional approach of loops. Where these looping techniques are used?Different types of looping techniques are used in the places where the user does not have to manipulate the structure of the code or the orders of the whole containers. Instead, the user has to print the elements for a single-use instance, and no in-place change occurs in the container. These can also be used for saving time and memory. Looping Techniques by using Python Data Structures:
Example: Output: 0 Joe 1 waited 2 for 3 the 4 train 5 , 6 but 7 the 8 train 9 was 10 late 11 .
Example: Output: What is this animal? this is tiger. What is this shape? this is square. What is this time? this is 11 o clock.
Example: Output: The key value pair by using items is : Joe waited for the train but the train was late
Example 1: Output: The list in sorted order is : 1 1 2 4 4 6 7 The list in sorted order (without duplicates) is : 1 2 4 6 7 Example 2: Output: Joe but for late the train waited was
Example 1: Output: The list in reversed order is : 21 19 17 15 13 11 9 7 5 3 1 Example 2: Output: 19 17 15 13 11 9 7 5 3 1 ConclusionIn this tutorial, we have discussed the different types of lopping techniques that are useful for saving memories and time. |
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/263493.html