-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew.py
More file actions
67 lines (52 loc) · 1.62 KB
/
new.py
File metadata and controls
67 lines (52 loc) · 1.62 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import csv
from math import inf
from anytree import Node, RenderTree, find_by_attr
def csv_tolist():
results = []
with open("some.csv") as csvfile:
reader = csv.reader(csvfile, delimiter=',') # change contents to floats
for row in reader: # each row is a list
results.append(row)
return results
def to_tree(results,origin, pos):
root = Node([origin, 0])
parentnode = root
for x in range(pos):
if x == 0:
for y in results:
if y[0] == root.name[0]:
node = Node([y[1], y[pos]], parent=parentnode)
else:
parentnode = node
for y in results:
if y[0] == parentnode.name[0]:
node = Node([y[1], y[pos]], parent=parentnode)
node = Node([y[1], y[pos]], parent=parentnode)
print(node)
print(node)
for pre, fill, node in RenderTree(root):
print("%s%s" % (pre, node.name))
return root
def find_next(results,next,origin, pos):
# next = ''
add = ''
min = inf
for x in results:
if x[0]==origin:
if min>float(x[pos]) and x[1] not in next:
min = float(x[pos])
add = x[1]
print(add)
next.append(add)
return next
def main():
next = []
results = csv_tolist()
to_tree(results,"NYC",3)
next.append("NYC")
# print(find_next(results,next,next[0],2))
# print(find_next(results,next, next[1], 3))
# print(find_next(results,next, next[2], 4))
# print(find_next(results,next, next[3], 5))
next.append("NYC")
main()