Home > Interesting, python > Never Write For-Loops Again

Never Write For-Loops Again

This is a challenge. I challenge you to avoid writing for-loops in every scenario. Also, I challenge you to find the scenarios that are so freaking hard to write anything else but a for-loop. Please share your findings. I’d like to hear about them.
It’s been a while since I started exploring the amazing language features in Python. At the beginning, it’s just a challenge I gave myself to practice using more language features instead of those I learned from other programming language. And things are just getting more fun! Not only the code become shorter and cleaner, but also code looks more structured and disciplined. I’ll get into those benefits more in this article.

Read more here-> https://medium.com/python-pandemonium/never-write-for-loops-again-91a5a4c84baf#.h6tgsaoce

Source:
http://pythonweekly.com

Advertisements
Categories: Interesting, python
  1. November 25, 2016 at 7:51 am

    cmon, rodnee. apart from being way easier for students to understand (if you want to teach generators later the same year, fine with me) the only universal alternative i know is recursion. in python for example, the standard recursion limit is 1000. you can change it, but why is it even there?

    and what exactly is the point of ditching for loops? is this about state? if we are going purely functional, lets just go purely functional and see if it isnt more trouble for most people. i think its exciting to try new things, when theyre not to ridiculously difficut– but lets talk about why anyone would do it– “better code readability?” pure nonsense. more compact perhaps– but so is apl.

    • November 25, 2016 at 4:56 pm

      I hear you. But there are times a list comprehension is actually neater than a for-loop. That said I was just as skeptic/curious when I read the article. Look at the comments at the end, the author admits “Never write for-loops” wasn’t the best title to use.

      I ain’t dropping *all* my for-loops just yet 🙂

      • November 25, 2016 at 5:08 pm

        indeed, thats all im saying. list comprehensions *are* really cool. python has a huge collection of features so you can do things 100 different ways, but everytime they add one it becomes the new “best practice.”

        i actually switched to python to get away from that– silly me, but i stayed for the incredible flexibility. now all we need is to make certain python 2 has a future. theres pypy, but a fork would be nice. its been years– i will never really appreciate the way strings are done in python 3.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: