Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

cons(a, b) constructs a pair, and car(pair) and cdr(pair) returns the first and last element of that pair. For example, car(cons(3, 4)) returns 3, and cdr(cons(3, 4)) returns 4.

def cons(a, b):
    def pair(f):
        return f(a, b)
    return pair

def car(f):
    def left(a, b):
        return a
    return f(left)

def cdr(f):
    def right(a, b):
        return b
    return f(right)

print(car(cons(3,4)))
print(cdr(cons(3,4)))
Comment

PREVIOUS NEXT
Code Example
Python :: pearson corr 
Python :: yapf ignore line 
Python :: binning dat adataframe 
Python :: how to loop over day name in python 
Python :: truncate add weird symbols in python 
Python :: get package share vs FindPackageShare 
Python :: creating a new folder in python 
Python :: os.remove directory 
Python :: python beep 
Python :: tqdm remove progress bar when done 
Python :: how to get started with python 
Python :: how to use Qtimer in thread python 
Python :: dataframe groupby to dictionary 
Python :: how to cycle through panes in tmux 
Python :: element not found selenium stackoverflow 
Python :: dataframe unique values in each column 
Python :: one hot encoder python 
Python :: python requests token x-www-form-urlencoded 
Python :: matplotlib remove y axis label 
Python :: schedule task to midnight python 
Python :: pythonic 
Python :: pytest installation windows 
Python :: ax set xtick size 
Python :: how to obtain the content of brackets 
Python :: how to send a message from google form to a python 
Python :: create directory python if not exist 
Python :: adaptive thresholding cv2 python 
Python :: undo cell delete kaggle 
Python :: all possible substring in python 
Python :: how to save a dictionary as a file in python 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =