Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a python 3 for loop one-liner that doesn't produce a list? [duplicate]

I'm brand new to python 3 & my google searches have been unproductive. Is there a way to write this:

for x in range(10):
  print(x) 

as this:

print(x) for x in range(10)

I do not want to return a list as the arr = [x for x in X] list comprehension syntax does.

EDIT: I'm not actually in that specific case involving print(), I'm interested in a generic pythonic syntactical construction for

method(element) for element in list
like image 637
neph Avatar asked Jan 18 '26 08:01

neph


1 Answers

No, there isn't. Unless you consider this a one liner:

for x in range(6): print(x) 

but there's no reason to do that.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!