► Write clean and Pythonic for, while, and “for each“ loops in Python
One of the easiest ways to spot a developer with a background in C-style languages who only recently picked up Python is to look at how they loop through a list.
In this tutorial you’ll learn how to take a “C-style“ (Java/PHP/C/C ) loop and turn it into a nice and “native“ Python loop.
You can use these techniques to refactor your existing Python for loops and while loops in order to make them easier to read and more maintainable.
You’ll learn how to use Python’s range()/xrange() and enumerate() built-ins to refactor your loops and to avoid having to keep track of loop indexes manually.
The main takeaways in this tutorial are:
• Writing C-style loops in Python is considered unpythonic. Avoid managing loop indexes and stop conditions manually if possible.
• Python’s for-loops are really “for-each” loops that can iterate over items from a container or sequence directly.
Read the complete tutorial at →
To get more Python Tricks and to discover the full potential of Python check out “Python Tricks: The Book“ at the link below.
FREE COURSE – “5 Thoughts on Mastering Python“
PYTHON TRICKS: THE BOOK
SUBSCRIBE TO THIS CHANNEL:
* * *
► Python Developer MUGS, T-SHIRTS & MORE:
FREE Python Tutorials & News:
» Python Tutorials:
» Python News on Twitter: @dbader_org
» Weekly Tips for Pythonistas:
» Subscribe to this channel:
3 views
1031
330
7 days ago 00:01:03 1
Надеясь привлечь в пустеющие стены храма новых прихожан, в церкви Святого Петра в британском городе Шипли стали проводить турнир
7 days ago 01:02:15 1
Квартирник НТВ у Маргулиса. Wildways. Выпуск от [НТВ] (16+)
7 days ago 00:03:35 1
Шаг.mp4
7 days ago 00:01:38 2
[Yung Meechy] YungMeechy - Belt Double G (Official Music Video)
7 days ago 00:13:00 1
[Kings and Generals] Czechoslovak Legion in Russia and its War to Return Home
7 days ago 00:02:51 1
Видео от ПЖТ
7 days ago 00:21:27 1
[EvilFluff ] Соло в статиках 5-го тира. Билд, актуальность, и их прибыльность? #альбиононлайн #альбион #статики
7 days ago 00:02:34 1
[CNBC Television] Elon Musk’s Twitter stake underscores that the company can be acquired: LightShed’s Greenfield
7 days ago 00:07:39 1
[House M.D.] Massage Therapy | House M.D..
7 days ago 00:03:01 25
[ABOKAI] Jinx Death「Arcane Season 2 AMV」Blind Spot
7 days ago 00:24:31 1
[DGB Media] DMV Franko Talks About Life & Music Scene In DMV, New Single “Don’t” Being Played On Radio + More
7 days ago 00:08:37 6
[Daily Dose Of Internet] Suspect Escapes Interrogation Room
7 days ago 00:00:36 7
Video by Emmanuelle Nurdin(480p) (5).mp4
7 days ago 00:09:24 2
Сборник - Печи, мангалы, барбекю, коптильни, тандыры
7 days ago 00:05:42 1
[MMO_insider] Albion Online #8 - Ленивая торговля
7 days ago 00:01:01 6
video by ASIA MARRY ME
7 days ago 00:15:45 1
[Bloxter] GOJO and SUKUNA Getting Rated by YUJI In Different ROBLOX Anime Games
7 days ago 00:03:09 23
Томаш Шмидт поблагодарил Лукашенко за предоставление убежища в Белоруссии
7 days ago 00:17:17 1
[Gaming Reviving] Jujutsu Kaisen: Cursed Clash - All Ultimate Attacks [w/ Season 1-2 DLC]
7 days ago 00:06:17 1
[CNBC Television] A Covid-19 outbreak near vital Chinese port could create ’perfect storm’ for rising prices
7 days ago 00:02:18 1
The Sudanese Armed Forces are displaying documents of captured Colombian mercenaries (including former soldiers) who were recrui