Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from operator import itemgetter
- from string import lower
- import sys
- if len(sys.argv)<2:
- print 'Use: python frecuencia.py -h, para mostrar ayuda'
- exit(1)
- if sys.argv[1] == '-h':
- print 'Use: python frecuencia.py [opciones]'
- print '-h\thelp'
- print '----------------------------------'
- print '-t [texto]\tPara realizar el analisis sobre un texto metido a mano(entrecomillado en caso de tener espacios entre palabras)'
- print '-f [file]\tPara realizar el analisis sobre un texto en un fichero'
- exit(1)
- diccionario ={'a':0, 'b':0, 'c':0, 'd':0, 'e':0, 'f':0, 'g':0, 'h':0, 'i':0, 'j':0, 'k':0, 'l':0, 'm':0, 'n':0, 'o':0, 'p':0, 'q':0, 'r':0, 's':0, 't':0, 'u':0, 'v':0, 'w':0, 'x':0, 'y':0, 'z':0,' ':0}
- if sys.argv[1] == '-t':
- text = sys.argv[2]
- elif sys.argv[1] == '-f':
- archivo = sys.argv[2]
- text=''
- try:
- file1=open(archivo,'at+')
- except:
- print 'No existe el fichero '.archivo
- exit(1)
- while True:
- foo = file1.readline()
- if len(foo)<=0:
- break
- foo = foo[0:len(foo)-2]
- text = text+foo
- else:
- print 'Use: python frecuencia.py [opciones]'
- print '-h\thelp'
- print '----------------------------------'
- print '-t [texto]\tPara realizar el analisis sobre un texto metido a mano(entre comillado en cado de tener espacios entre palabras'
- print '-f [file]\tPara realizar el analisis sobre un texto en un fichero'
- exit(1)
- print 'ANALISIS DEL TEXTO CIFRADO:'
- print text
- #Pasar a minusculas
- text1=''
- for x in text:
- text1 = text1 +(lower(x))
- text = text1
- #Letra a letra
- for x in text:
- diccionario[x]+=1
- print'\nLETRAS'
- for c in range(97,123):
- print '\033[1;91m'+chr(c)+':'+'\033[m', diccionario[chr(c)],'\t',
- if (c-96)%10 == 0:
- print ('')
- #Parejas
- i=0
- parejas = []
- for x in range(0,len(text)-1):
- if (text[x]!=' ') and (text[x+1]!=' '):
- parejas.append((text[x]+text[x+1]))
- print '\n\nPAREJAS'
- l = []
- for c in range(0,len(parejas)):
- #print '\033[1;91m'+l[c][0]+':'+'\033[m', l[c][1],'\t',
- l.append((parejas[c],parejas.count(parejas[c])))
- l1 = l[0:len(l)-1]
- for x in l1:
- if x[0] == parejas[c]:
- l.pop()
- l.sort(key=itemgetter(1))
- l.reverse()
- for c in range(0,len(l)):
- print '\033[1;91m'+l[c][0]+':'+'\033[m', l[c][1],'\t',
- if (c+1)%10 == 0:
- print '';
- print ('')
- print 'xxxxxxxxxxxxx'
- print 'FAT by xgusix'
- print 'xxxxxxxxxxxxx'
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement