You are reading a single comment by @lf and its replies. Click here to read the full conversation.
  • were you saying my function was very C-like?

    Yeah, in the sense of explicit iteration variables for i in range(...).

    foo[::d] is shorthand for foo[slice(None, None, d)] so it's indexing with a slice object with a stride of d.

    was also confused as to why you can't print an enumerate object until you put it into a list

    Iterations over objects in python3 almost always produce generators, which are objects that you can iterate over but produce their results lazily.

    Imagine that the code you had written did something like:

    for i, line in enumerate(funcdata[::dy]):
       if line == "something":
          break # exit early
    

    With an eager generator, you have to make all the pairs to iterate over only to discard most of them when you exit early. With a lazy generator, you can avoid that (and can even deal with an infinite stream of data as long as you terminate at some point).

  • Interesting - that probably stems somewhat from 'learning' to code with Java, VBA and then R at university (maths/stats), then trying to pick up Python in recent years. Most of my stuff i've done at work has been VBA in spreadsheets with financial data. I've never really learned properly how to write more advanced programs, all of the main stuff etc just confuses me.

    Explanation on enumerate makes sense and thanks for that, very helpful!

About

Avatar for lf @lf started