daily pastebin goal
74%
SHARE
TWEET

ai

a guest Oct 19th, 2018 71 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. def compression(l):
  2.     ocurrences,starting_index,value = 1,0,l[0]
  3.     #[1,2,3,4..12]
  4.     print("Total lista ", len(l))
  5.     for i in range(1,len(l)):
  6.         print("Indice que estoy recorriendo: ", i)
  7.         print("Valor en la lista: ", l[i])
  8.         if l[i] == value:
  9.             print("Es igual, sumo 1")
  10.             ocurrences += 1
  11.         elif ocurrences > 1:
  12.             print("Es distinto, ha habido mas de una ocurrencia")
  13.             new_tuple = (ocurrences, value)
  14.             for j in range(starting_index, i):
  15.                 del(l[j])
  16.             l.insert(starting_index,new_tuple)
  17.            
  18.             ocurrences,starting_index,value = 1,i,l[i]
  19.          
  20.         else:
  21.             print("No ha habido ocurrencias seguidas")
  22.             value = l[i]
  23.             ocurrences = 1
  24.             starting_index = i
  25. compression([1, 1, 1, 2, 1, 3, 2, 4, 4, 6, 8, 8, 8])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top