-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprecureDataToFeature.py
More file actions
38 lines (30 loc) · 938 Bytes
/
precureDataToFeature.py
File metadata and controls
38 lines (30 loc) · 938 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
# -*- coding: utf-8 -*-
import csv
import collections as cs
import sys
def handNumber(hand):
number = cs.defaultdict(lambda: -1)
number['グー'] = 0
number['チョキ'] = 1
number['パー'] = 2
return number[hand]
def printFeature(csvData, n = 1):
history = cs.deque([])
for row in csv.reader(csvData):
hand = row[0]
num = handNumber(hand)
length = len(history)
if length >= n:
if num != -1 and all([h != -1 for h in history]):
print num,
for i, h in enumerate(history):
print '{}:1'.format(h + 3 * i),
print
history.popleft()
history.append(num)
if __name__ == '__main__':
if len(sys.argv) != 2 or sys.argv < 1:
print 'Usage: python {} n(>= 1)'.format(sys.argv[0])
exit()
else:
printFeature(sys.stdin, int(sys.argv[1]))