python - How to return List in a single line -



python - How to return List in a single line -

i trying list of integers single line without spaces, able below code

import sys l = [1, 2, 3] in list: b = sys.stdout.write(str(a)) homecoming int(b)

but above code gives me out set of 1231, want output 123

does 1 have thought on how this?

if you're trying homecoming string of list items concatenated together, code should be:

l = [1, 2, 3] homecoming ''.join([str(item) item in l])

no need importing sys or writing stdout.

if output needs int, utilize

return int(''.join([str(item) item in l]))

i know looks little weird cast ints strings, ints, that's have if want concatenate everything.

python python-3.x

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -