Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7218751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:31:30+00:00 2026-05-28T21:31:30+00:00

Given colour = [ red, blue, green, yellow, purple, orange, white, black ] generate

  • 0

Given colour = [ “red”, “blue”, “green”, “yellow”, “purple”, “orange”, “white”, “black” ]
generate and print a list of 50 random colours. You will need to use the random module to get random numbers. Use range and map to generated the required amount of numbers. Then use map to translate numbers to colours. Print the result.

This is a question i’ve been given and here’s my code so far

colour = [ "red", "blue", "green", "yellow", "purple", "orange", "white", "black" ]

number=random.randint(1,9)

number.range(50)

i’m assuming this has made a variable that picks random numbers between 1-9, and then makes 50 of them ? i now need some way of linking the numbers to the colours.. i know this question is quite vague but if anyone could point me in the right direction, that would be awesome !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T21:31:31+00:00Added an answer on May 28, 2026 at 9:31 pm

    For some reason, your question requires use of map. It is difficult to help with this question without giving the answer directly, especially because these kinds of manipulations are one-liners. To start, using map and range to get a list of random numbers in the required range:

    >>> nums = map(lambda x : random.randint(0,7), range(50))
    >>> nums
    [6, 6, 2, 4, 7, 6, 6, 7, 1, 4, 3, 2, 6, 1, 1, 2, 2, 0, 7, 
    3, 6, 1, 5, 2, 1, 2, 6, 0, 3, 0, 2, 6, 0, 6, 3, 5, 0, 7, 
    2, 5, 4, 1, 0, 0, 1, 4, 3, 3, 0, 3]
    

    Observe that the argument to lambda, x is not used. That is at least one reason why I wouldn’t use map here. Then, using the list of numbers, map the indexing function onto the numbers to obtain the list of colours:

    >>> cols = map(lambda i: colour[i], nums)
    >>> cols
    ['white', 'white', 'green', 'purple', 'black', 'white', 'white', 
    'black', 'blue',     'purple', 'yellow', 'green', 'white', 
    'blue', 'blue', 'green', 'green', 'red', 'black', 'yellow', 
    'white', 'blue', 'orange', 'green', 'blue', 'green', 'white', 
    'red', 'yellow', 'red', 'green', 'white', 'red', 'white', 
    'yellow', 'orange', 'red', 'black', 'green', 'orange', 'purple', 
    'blue', 'red', 'red', 'blue', 'purple', 'yellow', 'yellow', 'red', 
    'yellow']
    

    The answer given by soulcheck, using random.choice() in a list comprehension, is by far the best way of determining the answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have: data Color = Blue | Green | Red | White | Yellow
given the following code: string[] colors = {red,green,blue,red,green,blue}; var distinctColors = (from c in
Let's say I have a 2D list that looks like this: [ ['Red','Green','Blue'], ['Red','Red','Green'],
Background: Given n balls such that: 'a' balls are of colour GREEN 'b' balls
I am tracking three color points - red, green and blue. I have currentFrames
I need to draw a circle onto a bitmap in a specific colour given
Given the following HTML: <!doctype html> <html> <body> <span style=background-color: blue;> Some text here
I try to color given area of bitmap. After show it on screen. Currently
Given a source color of any hue by the system or user, I'd like
Given that there are many sizes and color depths for different phones (even for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.