• Skip to primary navigation
  • Skip to content
  • Skip to footer
Eliannys Cermeño
  • Home
  • Post
  • About
    Eliannys Cermeño

    Eliannys Cermeño

    Technical Analyst at Stratesys

    • Linkedin
    • GitHub
    • Youtube

    How can you randomize the items of a list in place in Python?

    less than 1 minute read

    The random module provides a shuffle() function that returns a sequence with its elements randomly.

    Example:

    import random
    numbers = [1, 2, 3, 4, 5, 6,]
    random.shuffle(numbers)
    print(numbers)
    
    # Output:
    [4, 3, 6, 1, 5, 2]
    

    Reference

    Example and definition

    Tags: Python question

    Updated: July 15, 2021

    Twitter Facebook LinkedIn
    Previous Next

    You May Also Enjoy

    How do you write comments in python?

    less than 1 minute read

    A single line comment can be added by using the hash (#)character. The hash (#) is added for every line that should be commented. Example: #This is a comme...

    How will you convert a string to all lowercase?

    less than 1 minute read

    To convert String to lowercase, you can use lower()v function on the String. String.lower() function returns a string with all the characters of thi...

    What means list [-1]?

    less than 1 minute read

    Suppose: list = [2, 33, 222, 14, 25] print(list[-1]) Options: A) Error B) None C) 25 D) 2 Answer: C) 25. The index -1 corresponds to the last index ...

    Which of the following is an invalid statement?

    less than 1 minute read

    A) numbers = 1,000,000 B) numbers = 1000 2000 3000 C) numbers = 1000, 2000, 3000 D) numbers = 1,000,000 Answer: B) numbers = 1000 2000 3000 Whitespace i...

    • Linkedin
    • GitHub
    • Youtube
    • Feed
    © 2022 Eliannys Cermeño. Powered by Jekyll & Minimal Mistakes.