Reputation: 191
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?
Upvotes: 0
Views: 28
Reputation: 5048
Converting my comment to an answer:
You could use:
o = ', '.join(w+q)
and skip those loops.
Upvotes: 2
Reputation: 5236
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.
Upvotes: 1