Hello,

has there been consideration for implementing the following new
syntax:

      def my_fun(elements):
          results = []
          for elem in elements:
              ...
              continue if not is_valid(elem)
              ...
              results.append(result)
              break if len(results) == max_results
          return results

Or similarly:

      def iter_fun(elements):
          num_results = 0
          for elem in elements:
              ...
              continue if not is_valid(elem)
              ...
              yield result
              num_results += 1
              return if num_results == max_results


When there is an expression involved for the case of a `return`
or `raise` statement, I don't think it's such a great style,
because the conditional gets hidden off to the right.

      def myfun(val):
          return default_result if val not in known_vals
          ...
          return result

Alternatively, is there a good way I can implement this as a
preprocessor for myself?


Thanks
Manuel Barkhau
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to