Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Square Odd Python

### START FUNCTION
def square_odd(pylist):

    numbers = []
    for i in range(len(pylist)):
        item = int(pylist[i])
        if item % 2 == 1:
            numbers.append(item**2)

#     Using a list comprehension
#     numbers = [int(x)**2 for x in pylist if int(x)%2==1]

    return numbers
### END FUNCTION
Source by athena.explore-datascience.net #
 
PREVIOUS NEXT
Tagged: #Square #Odd #Python
ADD COMMENT
Topic
Name
5+2 =