1
a = [apple,[green,red,yellow]]

print(a[0]+ " available in these colours " + a[1[]])

how do I concatenate string with list in list items ?

expected result :-

apple available in these collars green red yellow
Rakesh
  • 81,458
  • 17
  • 76
  • 113
  • I don't think it's an exact duplicate of the suggestions. This is not a list of lists, but rather a list of a string and list of strings. The second suggestion is a bit more relevant, but it's part of the question here. – Ami Tavory Dec 18 '18 at 11:30

1 Answers1

3

Assuming you start with

a = ['apple',['green', 'red', 'yellow']]

Then a[0] is a string, and a[1] is a list of strings. You can change a[1] into a string using ', '.join(a[1]), which will concatenate them using a comma and a space.

So

a[0] + ' available in ' + ', '.join(a[1])

should work, as you can concatenate strings with +.

Ami Tavory
  • 74,578
  • 11
  • 141
  • 185