-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataann.py
52 lines (41 loc) · 1.37 KB
/
dataann.py
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
#Dataannotation test script - called dataann.py
#Script takes a dictionary consisting of number/word pairs and
#returns the words mapped to a unique number
#first line in input file begins with 195 land
#Description follows the code
#At Step 5, enter the number(s) desired to show the matching word(s).
#Load libraries here, such as pandas, matplotlib, etc. Path
#is needed to help this Mac find the datafile
from pathlib import Path
#Step 1
#set some variables to ease reading and writing of code
data_folder = Path("/Users/reginaldstuart/Documents/python")
file_to_open = data_folder / "data.txt"
#Step 2
#open the file containing the data to process
open_file = open(file_to_open, 'r')
#Step 3
#take the data in the file and create a dictionary called data
data = {}
for line in open_file:
val, keys = line.strip().split(' ', 1)
data.update(dict.fromkeys(keys.split(' '), val))
#Step 4
#reverse the key/value relationship so that we have everything in a format we like
rev_data = {}
for key, value in data.items():
rev_data.setdefault(value, []).append(key)
#Step 5
#get the records/data we want
first = rev_data['1']
second = rev_data['3']
third = rev_data['6']
#Step 6
#put our desires into a single tuple
sample = (first, second, third)
#Step 7
#crack the tuple
sample2 = first[0],second[0],third[0]
#Step 8
#print the string requested by the Boss.
print(*sample2)