int_main_list = [int(N) for N in main_list]
int_main_list_2 = [int(N) for N in main_string_2[2:]]
#print(intlist_main_string)
avg = sum(int_main_list) / ( len(int_main_list) -1)
print(avg)

avgg = sum(int_main_list_2) / ( len(int_main_list_2) -1)
print(avgg)


##CODE #1: the quickest/ Python-est:
values_0 = [N for N in range(10)]
distr_values_0 = [ sbm( str(N) , main_string_2[2:]).counter() for N in values_0 ]

num = 0
for L in range(len(values_0)):
	num += values_0[L] * distr_values_0[L]

avgg = float(num)/ float(sum(distr_values_0)) 
print(avgg)




#exit()

## CODE #2: The longest/ C++-est:
s = time.time()

for n in range( len_filenames ):
	with open(filenames[n]) as f:
		lines[n] = f.readlines()
	pi_str[n] = strconvert(lines[n])[0:1] + strconvert(lines[n])[2:-1] 

# NOTE: below n = 0, 1, 2 indexes the three lengths of Pi being considered, and  
# x = 0, 1, 2, ..., 9 are the input values to be plotted against. E.g. x vs. F_n(x).

domain = range(0,10)

#Defines an array of Class Instantiations: CL[n][x]
CL = [ [] ] * len_filenames
for n in range(len_filenames):
	CL[n] = [ sbm(x, pi_str[n] ) for x in domain ]


#Defines an array of Methodized classes: freq[n][x]
freq = [ [] ] * len_filenames
for n in range(len_filenames):
	freq[n] = [ element.jcount() for element in CL[n] ]
	#freq[n] = [ CL[n][x].jcount() for x in domain ]


norm_freq = [ [] ] * len_filenames
for n in range(len_filenames):
	norm_freq[n] = [ 100*element/sum(freq[n]) for element in freq[n] ]


# From their uses inside the for loops AT a given n: CL[n], freq[n] and norm_freq[n] 
    snippet_str[n] = strconvert(lines[n])[0:-1]

# NOTE: below n = 0, 1 indexes the two lengths of Pi being considered, and
# x = 0, 1, 2, ..., 9 are the input values to be plotted against. E.g. x vs. F_n(x).

domain = range(0, 10)

# Defines an array of Class Instantiations, CL[n][x],
# as made clear in the body of the for loop
CL = [[]] * len_filenames  # = [ [], [] ] since len_filenames == 2.

# This list has two elements, Cl[0] = CL[1] = [],
# each of which are empty LISTS, but will soon take form.

for n in range(len_filenames):
    CL[n] = [sbm(x, str_lines[n]) for x in domain]

#Defines an array of Methodized classes: freq[n][x]
freq = [[]] * len_filenames
for n in range(len_filenames):
    freq[n] = [element.jcount() for element in CL[n]]

norm_freq = [[]] * len_filenames
for n in range(len_filenames):
    norm_freq[n] = [100 * element / sum(freq[n]) for element in freq[n]]

hist = pygal.Bar(style=custom_0, legend_at_bottom=True)
hist1 = pygal.Line()

#hist = pygal.Bar(Style = blue)
lines =  []
for item in filenames:
	with open(item) as f:
		lines_item = f.readlines() 
		lines.append(lines_item )

str_lines = [] 
for item in lines:
	str_lines_item = strconvert(item)[0:1] + strconvert(item)[2:-1] 
	str_lines.append(str_lines_item)



CL = []
for item in str_lines:
	CL_item = [ sbm(x, item ) for x in domain ]
	CL.append(CL_item)


freq = []
for CL_n in CL:
	freq_n = [ element.jcount() for element in CL_n ]
	freq.append(freq_n)
	

norm_freq = [ ]
for freq_n in freq:
	norm_freq_n = [ 100*element/sum(freq_n) for element in freq_n ]
	norm_freq.append(norm_freq_n)

示例#5
0
len_filenames = len(filenames)
lines =  [''] * len_filenames
pi_str = [''] * len_filenames

for n in range( len_filenames ):
	with open(filenames[n]) as f:
		lines[n] = f.readlines()

	pi_str[n] = strconvert(lines[n])[0:1] + strconvert(lines[n])[2:-1] 



R = range(0,10)  # D = [0,1,2,..,9]
	

V_0 = [ sbm(r, pi_str[0] ) for r in R ]
V_1 = [ sbm(r, pi_str[1] ) for r in R ]
#V_2 = [ sbm(r, pi_str[2] ) for r in R ]


freq_0 = [ element.jcount() for element in V_0 ]
freq_1 = [ element.jcount() for element in V_1 ]
#freq_2 = [ element.jcount() for element in V_2 ]


norm_freq_0 = [100*element/sum(freq_0) for element in freq_0]
norm_freq_1 = [100*element/sum(freq_1) for element in freq_1]
#norm_freq_2 = [100*element/sum(freq_2) for element in freq_2]


示例#6
0
from jonmodule import Sub_in_main as sbm
import time

filename = 'pi_1000000.txt'
with open(filename) as f:
    lines = f.readlines()

main_string = ''.join(line.strip() for line in lines)
#main_string = main_string[2:]
sub_string = '121391'
#sub_string = '151087'
#sub_string = '052380'
#sub_string = '6666'

v = sbm(sub_string, main_string)

start = time.time()

print(v.location())
v.counter()

end = time.time()
delta_t_1 = (end - start)

start = time.time()
v.locationn()
v.counterr()

end = time.time()
delta_t_2 = (end - start)