Skip to content

Instantly share code, notes, and snippets.

@pedrogrande
Created March 13, 2017 00:24
Show Gist options
  • Save pedrogrande/79d46aab74f121dbdc77419ddc11b397 to your computer and use it in GitHub Desktop.
Save pedrogrande/79d46aab74f121dbdc77419ddc11b397 to your computer and use it in GitHub Desktop.
length_of_array = len(L)
con = {}
array_of_con = []
i = 0
k = 0
while (i < (length_of_array - 1)):
first_item = L[i]
second_item = L[i+1]
con[k] = con.get(k, 1)
if first_item == second_item:
con[k] = con.get(k) + 1
else:
k = k + 1
array_of_con.append(first_item)
i = i + 1
con_values = con.values()
max_value = max(con_values)
num_occurances = [i for i, w in enumerate(con_values) if w == max_value]
new_array = []
o = 0
while o < len(num_occurances):
new_array.append(array_of_con[num_occurances[o]])
o = o + 1
lowest_value = min(new_array)
length_of_con_values = len(con_values)
if L[0] == L[len(L) - 1]:
consecutive_numbers_of_first_and_last = con_values[0] + con_values[length_of_con_values - 1]
if consecutive_numbers_of_first_and_last > max_value:
max_value = consecutive_numbers_of_first_and_last
lowest_value = L[0]
elif consecutive_numbers_of_first_and_last == max_value:
if L[0] < lowest_value:
max_value = consecutive_numbers_of_first_and_last
lowest_value = L[0]
R = []
i = 0
while i < max_value:
R.append(lowest_value)
i += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment