Practice Python

Andre Müller gbs.deadeye at gmail.com
Wed May 10 08:11:24 EDT 2017


Hello,

1.) a short example for Python 3, but not exactly what they want.

def square(numbers):
    yield from sorted(n**2 for n in numbers)

numberlist = [99, 4, 3, 5, 6, 7, 0]
result = list(square(numberlist))

To solve this tutorial, you need a different way.
I'm just showing how sexy Python 3 is ;-)
Python 2.7 feels old... it is old. Please learn Python 3.

Greetings
Andre

Am 08.05.2017 um 08:52 schrieb gyrhgyrh100 at gmail.com:
> Python - Exercise 5
> 1. Write a function that gets a list (list) of numbers. The function returns a new list of ordered square numbers from the smallest to grow.
> For example, for the list [2, 4, 5, 3, 1] the function returns
> [25, 16, 9, 4, 1].
>
> 2. Write a function that receives a list (list) and a number. The function returns the number of times the number appears in the list.
> For example, for list [2, 4, 2, 3, 2] and number 2 will return 3 because number 2 is listed 3 times.
>
> The answers here:
>
> https://www.youtube.com/watch?v=nwHPM9WNyw8&t=36s


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20170510/328b1d54/attachment.sig>


More information about the Python-list mailing list