I would like to call again the function to return a new list with 5 results of sampled_list. Thank you guys
import random
emoji_list = ['π', 'π', 'π', 'π', 'π', 'π
', 'π', 'π€£','π', 'π', 'π', 'π', 'π', 'π', 'π', 'π₯°', 'π', 'π','π', 'π', 'π', 'π', 'π', 'π', 'π€ͺ', 'π€¨', 'π§', 'π€', 'π', 'π€©', 'π₯³', 'π', 'π₯Ί', 'π³', 'π₯Ά', 'π±']
sampled_list=random.sample(emoji_list, k=5)
def listToString(sampled_list):
# initialize an empty string
str1 = ""
# traverse in the string
for i in sampled_list:
str1 += i
# return string
return str1
Probably you wanted something like this:
Try it online!
import random
def emojiString():
emoji_list = ['π', 'π', 'π', 'π', 'π', 'π
', 'π', 'π€£','π', 'π', 'π', 'π', 'π', 'π', 'π', 'π₯°', 'π', 'π','π', 'π', 'π', 'π', 'π', 'π', 'π€ͺ', 'π€¨', 'π§', 'π€', 'π', 'π€©', 'π₯³', 'π', 'π₯Ί', 'π³', 'π₯Ά', 'π±']
return ''.join(random.sample(emoji_list, k = 5))
print(emojiString())
print(emojiString())
Output:
π§ππππ₯°
π₯Ίπππ€π₯Ά
If you want to accumulate several results into list do following:
Try it online!
import random
def emojiString():
emoji_list = ['π', 'π', 'π', 'π', 'π', 'π
', 'π', 'π€£','π', 'π', 'π', 'π', 'π', 'π', 'π', 'π₯°', 'π', 'π','π', 'π', 'π', 'π', 'π', 'π', 'π€ͺ', 'π€¨', 'π§', 'π€', 'π', 'π€©', 'π₯³', 'π', 'π₯Ί', 'π³', 'π₯Ά', 'π±']
return ''.join(random.sample(emoji_list, k = 5))
def emojiAddToList(l):
l.append(emojiString())
l = []
emojiAddToList(l)
emojiAddToList(l)
emojiAddToList(l)
print(l)
Output:
['π€©ππ§ππ€', 'π₯°π
π€£ππ', 'π³ππ€ππ']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With