V
V
Vlad Tanashchuk2020-06-15 06:29:30
Python
Vlad Tanashchuk, 2020-06-15 06:29:30

How to generate random text from words in a list?

Can you tell me which script is better to use to generate text from the list?
Let's say here is our list of a few words:

list = ["привет", "приветик", "надеюсь у вас всё хорошо", "лучше некуда"]

From it you need to get some text that will be randomly generated without repetition:
Hello, I hope you are doing well

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rabo, 2020-06-15
@Xaeruz

list = ["hello", "hello", "hope you're doing well", "the best"]

Kaif-name for the variable.
import random
_list = ["привет", "приветик", "надеюсь у вас всё хорошо", "лучше некуда"]
random.shuffle(_list)
helloString = ' '.join(_list)

shuffle returns None, I forgot

D
Developer, 2020-06-15
@samodum

A classic task at interviews for a random, non-repeating selection of elements from an array.
Are you a programmer or what?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question