I'm making a hashtag generation randomizer that can be used for Instagram using Python.
What I want to print like
#picture #art #gallery #goodart #sky #fashion
but actually the following code was printed.
['#picture', '#art', '#gallery', '#goodart', '#sky', '#fasion']
How can I print like this?
#picture #art #gallery #goodart #sky #fashion
My code is below.
import random
tag1 = ["#photo", "#art", "#picture"]
tag1_list = random.sample(tag1, 2)
tag2 = ["#artlover", "#goodart", "#gallery"]
tag2_list = random.sample(tag2, 2)
tag3 = ["#beautiful", "#fasion", "#sky"]
tag3_list = random.sample(tag3, 2)
all_tags = tag1_list tag2_list tag3_list
print(all_tags)
CodePudding user response:
Loop over all_tags
and print every tag one by one. Using end=" "
as parameter for the print()
function for having a whitespace at the end of every print instead of a newline
for tag in all_tags:
print(tag, end=" ")
CodePudding user response:
You could join
the list with a delimiter of ' '
:
print(' '.join(all_tags))