Answer the question
In order to leave comments, you need to log in
How to output non-repeating elements of a python list?
I want to display random 3 elements from the list so that they do not repeat.
import random
a = ["1", "2", "3", "4"]
random.shuffle(a)
print(a[:3])
Answer the question
In order to leave comments, you need to log in
The code works, but it outputs this: ['2', '3', '1']
And I need it without: ['', '', '']
int(''.join(['2', '3', '1'])) # ['2', '3', '1'] можно заменить на a[:3]
# 231
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question