-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
39 lines (30 loc) · 729 Bytes
/
util.py
File metadata and controls
39 lines (30 loc) · 729 Bytes
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
from pair import nil, Pair
def pair_to_list(pair):
if pair == nil:
return []
return [pair.first] + pair_to_list(pair.rest)
def last(pair):
return pair_to_list(pair)[-1]
def except_last(pair):
return pair_to_list(pair)[:-1]
def map_(seq, fn):
new_seq = []
for i in range(len(seq)):
new_seq.append(fn(seq[i]))
return new_seq
def second(pair):
return pair.rest.first
def iota(n):
arr = []
for i in range(n):
arr.append(i)
return arr
def list_to_pair(seq):
pair = nil
for item in reversed(seq):
pair = Pair(item, pair)
return pair
def unique(seq):
return list(set(seq))
def all_distinct(seq):
return len(seq) == len(unique(seq))