Created
February 22, 2015 20:23
-
-
Save devvyn/8ad244de2ec0f43d7e30 to your computer and use it in GitHub Desktop.
code sketch: grab a CSV file with a column called "OTV SKU#" and split the characters in all the values into a character tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from CsvFileModel import CsvFileModel # available from https://gist.github.com/devvyn/759f08e3d83e4cf8f7ef | |
import json | |
import yaml | |
import collections | |
class StringTree(object): | |
def __init__(self): | |
c = CsvFileModel('csp.csv') | |
skus = list(x.strip() for x in c['OTV SKU#']) | |
print("SKU count: %i" % len(skus)) | |
charset = set(''.join(skus)) | |
print("Character set: %s" % charset) | |
d = dict() | |
j = d | |
for sku in skus: | |
for position, char in enumerate(sku): | |
j = j.setdefault(char, dict()) | |
j = d | |
print(d.keys()) | |
print(yaml.dump(d)) | |
self.skus = skus | |
self.data = c | |
self.tree = d | |
self.charset = charset | |
if __name__ == '__main__': | |
d = StringTree() | |
data = d.tree | |
with open('sku_codes.yml', 'w') as outfile: | |
yaml.dump(data, outfile, default_flow_style=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hard to read. Looks like
j
is being reassigned multiple times without read.