One-liner object comprehension in python3

Viewed 37
names = ""
for p in portals: names = names + str(p)

Ie there a one-liner pythonic-way to achieve this ?

1 Answers

Yes, you can use the str.join() method:

"".join(str(p) for p in portals)

Do note that there is even a more pythonic way to write

names = names + str(p)

and that way is

names += str(p)
Related