Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def compression(l):
- ocurrences,starting_index,value = 1,0,l[0]
- #[1,2,3,4..12]
- print("Total lista ", len(l))
- for i in range(1,len(l)):
- print("Indice que estoy recorriendo: ", i)
- print("Valor en la lista: ", l[i])
- if l[i] == value:
- print("Es igual, sumo 1")
- ocurrences += 1
- elif ocurrences > 1:
- print("Es distinto, ha habido mas de una ocurrencia")
- new_tuple = (ocurrences, value)
- for j in range(starting_index, i):
- del(l[j])
- l.insert(starting_index,new_tuple)
- ocurrences,starting_index,value = 1,i,l[i]
- else:
- print("No ha habido ocurrencias seguidas")
- value = l[i]
- ocurrences = 1
- starting_index = i
- compression([1, 1, 1, 2, 1, 3, 2, 4, 4, 6, 8, 8, 8])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement