Skip to content

Instantly share code, notes, and snippets.

@Abhinay-g
Created October 9, 2017 17:32
Show Gist options
  • Save Abhinay-g/c3acd3b9fd2edfb5fbbbfd4b4af601bc to your computer and use it in GitHub Desktop.
Save Abhinay-g/c3acd3b9fd2edfb5fbbbfd4b4af601bc to your computer and use it in GitHub Desktop.
function : ord('A') give ASCII value of 65
ord('a') give ASCII calue of 97
reverse dunction as ord() is chr()
chr(65) = 'A'
chr(97) = 'a'
----------------------------------------------
function map() :
this function used to map data from one format to other
list(map(int,list_of_string)) : this will return list of integer
list(map(int,char(string_value)) : this will convert string into list of integer
Syntax : map(Function,iterable)
----------------------------------------------
function filter():
Syntax for this is same as map
it just check some validation on data in iterable and then return the same value
so map() is used to tranform data and filter() is used to select data on some contion
example :
print(list( filter((lambda x: x < 0), range(-5,5)))) it will select [-5, -4, -3, -2, -1]
print(list(map((lambda x:x*x),range(1,5)))) it will give [1, 4, 9, 16]
-----------------------------------------------
function reduce():
this will reduce data to a single value :
it will take one element and its successor and perform operation, this continues till single value
from functools import reduce <*Note this package is required to import >
print (reduce( (lambda x, y: x * y), [1, 2, 3, 4] ))
op = 1*2*3*4*=24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment