The code from Artyom’s answer does not fulfill the original condition of the problem: " ... display a list of words in a random order. All words from the presented list should be printed on the screen without repetitions ... because repetitions from the list should be printed - there is no check for already selected items . Slightly correct:
import random spisok = ["Alex", "Kate", "Love", "World", "Peace", "Putin",] empty_list = list() count = len(spisok) schetchik = 0 while count != schetchik: for i in spisok: item = random.choice(spisok) if item in empty_list: print("Есть такие данные в новом списке!") else: empty_list.append(item) schetchik += 1 print(empty_list) # можно оставить вывод в for - увидим все попытки поиска, либо вывести из цикла.
As the authors have already noted in the comments, there is a more concise and practical option with creating a slice of the original list:
import random spisok_slov = ["кот", "кот", "код", "код", "ток", "ток", "ток", "ток", "тук-тук", "мак", "крот", "плот", "кнут"] final_no_repeat_list = list(set(spisok_slov[:])) random.shuffle(final_no_repeat_list) print(final_no_repeat_list)
randitem
absent inspisok
? It seems like he will always be there - we take from him. Soempty_list += randitem
will never be executed) - BOPOH