Python suggest change

Functional Programming

Functional programming decomposes a problem into a set of functions. Ideally, functions only take inputs and produce outputs, and don’t have any internal state that affects the output produced for a given input.below are functional techniques common to many languages: such as lambda, map, reduce.

Lambda Function

An anonymous, inlined function defined with lambda. The parameters of the lambda are defined to the left of the colon. The function body is defined to the right of the colon. The result of running the function body is (implicitly) returned.

s=lambda x:x*x
s(2)    =>4

Map Function

Map takes a function and a collection of items. It makes a new, empty collection, runs the function on each item in the original collection and inserts each return value into the new collection. It returns the new collection.

This is a simple map that takes a list of names and returns a list of the lengths of those names:

name_lengths = map(len, ["Mary", "Isla", "Sam"])
print(name_lengths)    =>[4, 4, 3]

Reduce Function

Reduce takes a function and a collection of items. It returns a value that is created by combining the items.

This is a simple reduce. It returns the sum of all the items in the collection.

total = reduce(lambda a, x: a + x, [0, 1, 2, 3, 4])
print(total)    =>10

Filter Function

Filter takes a function and a collection. It returns a collection of every item for which the function returned True.

[i for i in filter(lambda x:x>4,arr)]    # outputs[5,6]

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents
32 Set
46 Enum
105 Stack
119 Mixins
121 ArcPy
127 Arrays
139 Neo4j
141 Curses
146 heapq
155 Audio
156 pyglet
158 ijson
161 Flask
164 pygame
167 Gzip
168 ctypes
178 Functional Programming
187 shelve
  ↑ ↓ to navigate     ↵ to select     Esc to close