Guest User

refactor

a guest
Aug 12th, 2018
111
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Special(object):
  2.     special_characters = {
  3.         '1': 'i',
  4.         '3': 'e',
  5.         '4': 'a',
  6.         'q': 'k',
  7.         '0': 'o',
  8.         'f': 'w',
  9.         'ą': 'a',
  10.         'ę': 'e',
  11.         'ć': 'c',
  12.         'ś': 's',
  13.         'ż': 'z',
  14.         'ź': 'z',
  15.         'ł': 'l',
  16.         'ó': 'o',
  17.         '8': 'b',
  18.         '@': 'a'
  19.     }
  20.  
  21.     def refactor(self, word):
  22.         word = word.replace(" ", "").lower()
  23.         wordlist = list(word)
  24.         index = 0
  25.         last_letter = wordlist[0]
  26.         for lt in wordlist:
  27.             if lt in self.special_characters:
  28.                 wordlist[index] = self.special_characters.get(lt)
  29.             if last_letter == wordlist[index] and index != 0:
  30.                 del wordlist[index]
  31.                 print(wordlist)
  32.                 print(last_letter)
  33.                 print(index)
  34.                 continue
  35.             last_letter = wordlist[index]
  36.             index += 1
  37.             print(wordlist)
  38.             print(last_letter)
  39.             print(index)
  40.         word = "".join(wordlist)
  41.         return word
RAW Paste Data