Code Snippet: Shuffle Strings

From Coder Merlin
Jump to navigation Jump to search

Shuffle an Array of Strings[edit]

Swift[edit]

let verbs = ["walk", "jump", "run", "swim", "dance"]
let shuffledVerbs = verbs.shuffled()
for verb in shuffledVerbs {
    print(verb)
}

Python[edit]

import random
verbs = ["walk", "jump", "run", "swim", "dance"]
random.shuffle(verbs)
print(verbs)


CoderMerlin™ proudly recommends:
HintIcon.png

Your purchase via these links helps keep  Coder Merlin™ 's orbuculum ablaze. As an Amazon Associate we earn from qualifying purchases. Thank you for your support!


Designed with pride in Silicon Valley, CA, USA