Skip to content

Instantly share code, notes, and snippets.

Created May 3, 2016 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/28d5fab8b59ddcb3bcfc7befa63a5881 to your computer and use it in GitHub Desktop.
Save anonymous/28d5fab8b59ddcb3bcfc7befa63a5881 to your computer and use it in GitHub Desktop.
def rle(str):
z=""
for i in str:
if i in z:
print("")
else:
z=z+i
for i in z:
ch=""
c=0
k=0
while k<len(str):
if i == str[k]:
c=c+1
k=k+1
print(c, i, end=" ")
return(ch)
@lovasoa
Copy link

lovasoa commented May 3, 2016

Si tu veux vraiment faire comme ça...

boucle 1

  • ta première condition, i in z n'est pas bonne. Tu veux juste vérifier si i est le dernier caractère de z.
  • pas besoin de print vide

boucle 2

  • Ton k ne parcourt pas les bonnes valeur. Il ne doit pas commencer à 0, mais à l'endroit où tu es dans ton parcours de str. Tu dois sortir de ta boucle dès que tu rencontre un caractère différent.

Notes

  • Donne des noms plus explicites à tes variables, tu te perdras moins.
  • N'appelle pas de variable str. str est une fonction, en python.
  • Ne mets pas de print. Crée ta chaîne de retour au fur et à mesure, et retourne-là à la fin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment