View the step-by-step solution to:

Question

I need someone to rewrite the following code with list comprehension:


list1 = [4, 7, 12, 8,

25]

list2 = []

for x in list1:

  if x > 10:

    list2.append(x*2)


Thanks.

Top Answer

View the full answer
Screenshot_1.jpg

list1
= [4, 7, 12, 8, 25]
2
list2 = [2*x for x in list1 if x>10]
print (list1)
4
print (list2)
[4, 7, 12, 8, 25]
[24, 50]
Program finished with exit code 0
Press ENTER to exit console.

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question