Для названия вашего вопроса:
как полная программа
from random import sample
print(sample((s:=eval(input())),len(s)))
Объяснение
from random import sample Imports the sample function only in order to preserve speed.
print( Print out ...
sample( Shuffle randomly this list...
(s:= Python 3.8's assignment eval (assign to s while still evaling)
eval(input()) Evalulate the input, which is a Python list
),
len( Take the length of ...
s the input
)
)
)
Попробуйте онлайн!
Как анонимная лямбда
lambda x:sample(x, len(x))
from random import sample
Объяснение
lambda x: Define a lambda that takes in one argument named x
sample( Shuffle randomly
x, The one argument, which is a list
len( The length of ...
x The one argument, which is a list
)
)
from random import sample Import the sample function
Попробуйте онлайн!
как функция
def e(x):return sample(x, len(x))
from random import sample
Объяснение
def e(x): Define a function named e with one argument named x
return Set the functions value to be ...
sample( Shuffle a list
x, The one argument, which is a list
len( Length of ...
x The one argument; x
)
)
from random import sample Import the sample function
Попробуйте онлайн!
Для вашего первого вопроса в теле вашего вопроса:
Невозможно отсортировать список с помощью модуля random
, так как он предназначен для случайных функций, а не для сортировки. Однако вы можете использовать функцию Python sorted()
, которая сортирует список.
как полная программа
print(sorted(eval(input())))
Объяснение
print( Print out ...
sorted( The sorted version of ...
eval( The evaluated version of ...
input() The input
)
)
)
Попробуйте онлайн!
Как анонимная лямбда
lambda x:sorted(x)
Объяснение
lambda x: Declare a lambda with one argument, x
sorted( Return the sorted value of...
x The lambda's argument
)
Попробуйте онлайн!