Created
February 27, 2018 02:07
-
-
Save jamesbiederbeck/a95bb59d5a53596f8387d2304d1fa75c to your computer and use it in GitHub Desktop.
This file contains 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
def getcounts(filepath = ""): | |
"""This will read a list of barcodes, and flatten to a list of | |
all the barcodes and how many times each one is in the list.""" | |
while not filepath: #ensure a filepath gets specified | |
print("This will read inventory counts from a list of barcodes/SKU's.") | |
filepath = input("Enter the path to the file you would like to parse.") | |
with open(filepath) as f:#open the file | |
data = f.read() | |
data = data.rstrip()#remove trailing newlines | |
data = data.split("\n")#split the string into a list of lines | |
#initialize dictionary of part numbers and counts | |
countsdict ={} | |
#This goes through the list of part numbers, and makes sure each has an | |
#entry in the dictionary. | |
for line in set(data): | |
countsdict[line] = 0 | |
#Increment count for each instance of the sku in the list of part numbers | |
#found | |
for line in data: | |
countsdict[line.split("\t")[0]] +=1 | |
print("Found",len(countsdict),"items in the barcode list!") | |
return countsdict |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment