Skip to content

Instantly share code, notes, and snippets.

@Ra1d7
Created January 31, 2017 16:43
Show Gist options
  • Save Ra1d7/f46fdffc4f75f6c31dfba797da0bc16a to your computer and use it in GitHub Desktop.
Save Ra1d7/f46fdffc4f75f6c31dfba797da0bc16a to your computer and use it in GitHub Desktop.
prints to you how many characters are in a string or a file
decid = input('would you like to analyze a string or a file?')
def printit(cheer):
if cheer is not None or cheer != ' ':
if textls.count(cheer) != 0:
print(cheer + ":" + str(textls.count(cheer)))
elif cheer is None:
print("space:" + str(textls.count(cheer)))
elif cheer == '\n':
print('new lines:' + str(textls.count(cheer)))
if 'string' in decid:
text = input("Enter a string to analyze: ").lower()
textls = list(text)
elif 'file' in decid:
path = input('Enter file path to analyze: ')
with open(path, 'r') as f:
text = f.read().lower()
textls = list(text)
chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '', ']', '[', '\'',
'}', '{', '\"', '\n','!','@','#','$','%','+','-','*','/','.','<','>','=','(',')',':',';']
for x in chars:
printit(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment