A
A
Anton2021-11-01 18:56:48
Python
Anton, 2021-11-01 18:56:48

How to collect a string from several pieces in python?

Greetings!
Please tell me how to collect a string randomly from several pieces, for example:
Pieces of a string:
AAA BBB CCC DDD EEE FFF GGG HHH The
desired result of random gluing:
CCCAAAFFFGGGHHHBBBEEEDDD
HHHDDDGGGEEEAAACCCСBBBFFF

Without repeating a piece of a string.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-11-01
@boypush

from random import sample

arr = [ 'AAA', 'BBB', 'CCC', 'DDD', 'EEE', 'FFF', 'GGG', 'HHH' ]
string = ''.join(sample(arr, k=len(arr)))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question