Ubuntu Pastebin

Paste from hoxily at Thu, 29 Jan 2015 11:15:03 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
>>> list()
[]
>>> l1=list()
>>> l2=list()
>>> l1 == l2
True
>>> '1' in ['1']
True
>>> '1' in ['2']
False
>>> car = lambda list: list[0]
>>> car
<function <lambda> at 0x021B51E0>
>>> car(['1'])
'1'
>>> car([1,2,3])
1
>>> cdr = lambda list: list[1:]
>>> cdr([])
[]
>>> cdr(['1'])
[]
>>> cdr([1,2])
[2]
>>> cdr([]) == []
True
>>> def match_list(element, list):
...     if list == []:
...             return 0
...     elif element == car(list):
...             return 1
...     else:
...             return match_list(element, cdr(list))
...
>>> a=match_list('1', ['1'])
>>> a
1
>>> b=match_list('1', ['2'])
>>> b
0
Download as text