简体   繁体   中英

Outputting values from two lists (python)

I need to display all the letters in both list like this:

a, b, c, d, e, f

This is the code:

w = 'abc'
q = 'efg'
o = ''

for i in w:
    y = ', '.join(w)

for i in q:
    u = ', '.join(q)

o = y + u

print(o)

but I am getting: a, b, ce, f, g

How to do that?

Converting my comment to an answer:

You could use:

o = ', '.join(w+q)

and skip those loops.

Try this:

w = 'abc'
q = 'efg'
o = ', '.join(w+q)
print(o)

No need to iterate through either string with the for loop, unless of course this is an abstraction of your use case and you will eventually need to do this to things that aren't strings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM