Question

In python using list comprehension, given a list of number, return the list with all even...

In python using list comprehension, given a list of number, return the list with all even numbers doubled, and all odd numbers turned negative. [72, 26, 79, 70, 20, 68, 43, -71, 71, -2] -> [144, 52, -79, 140, 40, 136, -43, 71, -71, -4]

0 0
Add a comment Improve this question Transcribed image text
Answer #1
lst = [72, 26, 79, 70, 20, 68, 43, -71, 71, -2]
result = [2*x if x%2==0 else -x for x in lst]
print(result)

Add a comment
Know the answer?
Add Answer to:
In python using list comprehension, given a list of number, return the list with all even...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • o Write a function that outputs even numbers less than the input number. • Function name...

    o Write a function that outputs even numbers less than the input number. • Function name should be 'evenprint'. • A number is given as input to the function. . The function must return a list of even numbers def evenprint(num): #write statement >[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74,...

  • In python,Using list comprehension create an expression that sums up all the factors of an positive...

    In python,Using list comprehension create an expression that sums up all the factors of an positive integer number. For example, if the number is 6, then the output should be 12 (i.e., 1+2+3+6 =12). Your answer should be only one line of code.

  • Given a list of integers, return a list where each integer is added to 1 and...

    Given a list of integers, return a list where each integer is added to 1 and the result is multiplied by 10. You must use a list comprehension math1([1, 2, 3]) → [20, 30, 40] math1([6, 8, 6, 8, 1]) → [70, 90, 70, 90, 20] math1([10]) → [110] Complete in Python code the starter code is listed bellow def math1(lst):    return lst print(math1([1, 2, 3])) # [20, 30, 40] print(math1([6, 8, 6, 8, 1])) # [70, 90, 70,...

  • Write a python nested for loop that prints out the following pattern 100 99 98 97...

    Write a python nested for loop that prints out the following pattern 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33...

  • USING PYTHON!! Given an even number x, we keep dividing it by 2 until it becomes...

    USING PYTHON!! Given an even number x, we keep dividing it by 2 until it becomes an odd number, and then print out the last even number. For example, if x = 12, 12/2 = 6, and 6/2 = 3.

  • Complete function long_list_printer.print_list(). When it's finished, it should be able to print this list, a =...

    Complete function long_list_printer.print_list(). When it's finished, it should be able to print this list, a = [ [93, 80, 99, 72, 86, 84, 85, 41, 69, 31], [15, 37, 58, 59, 98, 40, 63, 84, 87, 15], [48, 50, 43, 68, 69, 43, 46, 83, 11, 50], [52, 49, 87, 77, 39, 21, 84, 13, 27, 82], [64, 49, 12, 42, 24, 54, 43, 69, 62, 44], [54, 90, 67, 43, 72, 17, 22, 83, 28, 68], [18, 12, 10,...

  • Exercise 5.5.10 Perform model selection for the blood pressure data in Table 3.1 using Ri and ste...

    topic: model selection on applied linear regression Exercise 5.5.10 Perform model selection for the blood pressure data in Table 3.1 using Ri and stepwise selection algorithm. Compare the results with all possible subsets regression. 47 3.8 Exercises Age Weight Pulse Blood pressure 21 7 88 24 56 70 25 65 72 28 53 60 32 67 60 35 80 70 7 57 68 38 58 64 39 68 75 160 135 140 118 134 60 67 1 64 8 42...

  • RANGES FREQUENCY RELATIVE FREQUENCY CUMULATIVE REL. FREQ. 1 - 10 11 - 20 21 - 30 31 - 40...

    RANGES FREQUENCY RELATIVE FREQUENCY CUMULATIVE REL. FREQ. 1 - 10 11 - 20 21 - 30 31 - 40 41 - 50 51 - 60 61 - 70 71 - 80 81 - 90 91 - 100 '= 100 DATA VALUES?? SO, WHAT DOES A FREQUENCY TABLE TELL US? If you wrote each of the above data values on a ping pong ball,, put them in a jar and blindly pulled one out: What is the probability that this ball...

  • Infinite Spiral of Numbers (due 17 Feb 2020) HELLO, WE ARE USING PYTHON 3 TO COMPLETE...

    Infinite Spiral of Numbers (due 17 Feb 2020) HELLO, WE ARE USING PYTHON 3 TO COMPLETE THIS PROJECT!! PLEASE FOLLOW CODE SKELETON AS GIVEN AT THE END. THIS IS DUE 17TH FEB 2020, ANY AND ALL HELP WOULD BE GREATLY APPRECIATED, THANK YOU! Consider the natural numbers laid out in a square spiral, with 1 occupying the center of the spiral. The central 11 x 11 subset of that spiral is shown in the table below. 111 112 113 114...

  • C++

    You are given a file results.txt with the results of an experiment as a set of integers. You need to separate these results into three categories: negative integers, even positive integers, and odd positive integers. A sample of the file results.txt is shown below:    52    49   -22    31   -66    41   -94   -45   -91   -81    65    39   -37    90   -94   -12   -24    53    59   -63    -2   -11    29    42    51   -45    36    31   -68   -77     0    92   -32    17   -56    51  ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT