Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

halkazi

  • 3 years ago

Exercise 2.10.1 says "1. Write a list comprehension that prints a list of the cubes of the numbers 1 through 10." One answer is : >>> [x*x*x for x in [1,2,3,4,5,6,7,8,9,10]] [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000] Is there a better way to do this? Can I use while or for instead of listing out out all the numbers?

  • This Question is Closed
  1. estudier
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 2

    [x**3 for x in range(1,11)]

  2. halkazi
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks. That's way better.

  3. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy