0

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?

3
  • Use join(w) without loop instead? Commented Nov 24, 2014 at 23:40
  • 1
    why not simply ','.join(w+q) ? Commented Nov 24, 2014 at 23:41
  • 1
    @DRC you could make that an answer. Commented Nov 24, 2014 at 23:44

2 Answers 2

2

Converting my comment to an answer:

You could use:

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

and skip those loops.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.