0

I have a list of strings that contain a letter and number pair, for example a=["B8", "C1", "B4", "A3"]

I'd like to be able to use this list and combine it (without brackets, commas, or quotation marks) with a base string "You have" in a print statement to tell the user You have B8 C1 B4 A3

It doesn't seem possible to do this using the .join() and .append() methods.

2
  • Nothing is as it seems ;-) Commented Oct 29, 2014 at 0:04
  • Please show how you have tried, and in what way(s) they failed. Commented Oct 29, 2014 at 0:06

3 Answers 3

1

str.format and str.join will do exactly what you want:

a = ["B8", "C1", "B4", "A3"]
print("You have {}".format(" ".join(a)))

In [6]: a=["B8", "C1", "B4", "A3"]
In [7]: print("You have {}".format(" ".join(a)))
You have B8 C1 B4 A3
Sign up to request clarification or add additional context in comments.

Comments

0
a=["B8", "C1", "B4", "A3"]
print "You Have " + " ".join(a)

Comments

0
a=["B8", "C1", "B4", "A3"]
for item in a:
    print 'You have',item

Hope this was helpful.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.