-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple.py
88 lines (75 loc) · 1.79 KB
/
simple.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import re
#---------------------------------------------------
print "\nUnikat"
def uniq_elements(sequence):
print len(set(sequence))
#test
uniq_elements('tescikkk')
uniq_elements(['a', 'b', 'a', 'd', 'c'])
uniq_elements((1,2,3,4,5,1,2,3,6))
uniq_elements(set([1,2,4,3,2,1,3,2]))
#---------------------------------------------------
print "\nMini slowniczek"
def freq_dic(sequence):
dictionary = {}
for i in sequence:
dictionary[i] = 0
for i in sequence:
dictionary[i] = dictionary[i] + 1
print dictionary
#test
freq_dic("abracadabra")
freq_dic("tescikkk")
#---------------------------------------------------
print "\nSufiksy"
def suffixes(string):
suffixes_list = []
for i in range(0, len(string)):
word = ""
for j in range(i, len(string)):
word = word + string[j]
suffixes_list.append(word)
print suffixes_list
#test
suffixes("banana")
suffixes("tescikkk")
#---------------------------------------------------
print "\nBi"
def bigram(string):
bigrams_list = []
for i in range(0, len(string) - 1):
word = string[i] + string[i+1]
bigrams_list.append(word)
return bigrams_list
def bigrams(sequence):
bigrams_list = []
if isinstance(sequence, basestring):
print bigram(sequence)
else:
for element in sequence:
print bigram(element)
#test
bigrams("banana")
bigrams(("abcdef","ghijk", "lmnopr"))
bigrams(["abcdef","ghijk","lmnopr"])
bigrams(set(["abcdef","ghijk","lmnopr"]))
#---------------------------------------------------
print "\nEnigma"
def enigma():
dictionary = {}
i = 0
text = sys.stdin.readline()
text = text.strip()
text = re.sub('[ ]{2,}', ' ', text)
text = text.split(" ")
print text
for word in text:
if not word in dictionary:
dictionary[word] = i
i = i + 1
print dictionary[word]
#test
enigma()