Advertisement
Aikiro42

Untitled

Jan 26th, 2020
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. import sys
  2.  
  3. string = input()
  4. if len(string) == 0:
  5. print('COMPRESSION FAILED')
  6. sys.exit()
  7.  
  8. # step1 = []
  9. step1 = ''
  10. # for word in string.split(' '): // I recommend you don't split the string immediately
  11. for i in range(len(string)): # For each character in string
  12. # if '12' in word:
  13. # twelve = ''
  14. # f = word.find('12')
  15. # twelve += (list(word).pop(f) + list(word).pop(f+1))
  16. # step1.append(twelve)
  17. # The instructions state that you should just include the string '12' and all alpha characters
  18. if string[i].isalpha() or string[i] == ' ':
  19. step1 += string[i] # add character to step1 if it's alphanumeric
  20. else:
  21. # if it's the substring '12'
  22. if i + 1 < len(string):
  23. if string[i] == '1' and string[i + 1] == '2': # current string is '1', next string is '2'
  24. step1 += string[i]
  25. if 0 < i - 1:
  26. if string[i] == '2' and string[i - 1] == '1': # current string is '2', prev string is '1'
  27. step1 += string[i]
  28.  
  29. # else:
  30. # alpha = ''
  31. # for c in word:
  32. # if c.isalpha():
  33. # alpha += c
  34. # if len(alpha) > 0:
  35. # step1.append(alpha)
  36.  
  37. if len(step1.strip()) == 0:
  38. print('COMPRESSION FAILED')
  39. sys.exit()
  40. # print('STEP 1: ',' '.join(step1), sep='')
  41. print('STEP 1: {}'.format(step1))
  42.  
  43. # step1 = ' '.join(step1) # since step1 is a string
  44. step2 = ''
  45. for char in step1:
  46. # if char.isalpha(): # you can lowercase numbers, don't worry
  47. # if char in 'aeiouAEIOU':
  48. if char.lower() in 'aeiou': # more efficient
  49. step2 += char.upper()
  50. else:
  51. step2 += char.lower()
  52. # else:
  53. # step2 += char
  54. if len(step2.strip()) == 0:
  55. print('COMPRESSION FAILED')
  56. sys.exit()
  57. print('STEP 2: ', step2, sep='')
  58.  
  59. # step3a = []
  60. # step3b = []
  61. # Stick to proper naming conventions
  62. odd_words = []
  63. even_words = []
  64. step2 = step2.split(' ')
  65. # for word in step2:
  66. i = 0
  67. while i < len(step2): # easier
  68. # if step2.index(word) % 2 == 0:
  69. word = step2[i]
  70. if word == '':
  71. del step2[i]
  72. else:
  73. if i % 2 == 0:
  74. oddw = ''
  75. # for c in list(word):
  76. for j in range(len(word)):
  77. # if list(word).index(c) % 2 == 0:
  78. if j % 2 == 0:
  79. # oddw += c
  80. oddw += word[j]
  81. # step3a.append(oddw)
  82. odd_words.append(oddw)
  83. else:
  84. # step3b.append(word[len(word)//2:])
  85. even_words.append(word[len(word)//2:])
  86. i += 1
  87.  
  88. # print('STEP 3: ', ' '.join(step3a), '#', ' '.join(step3b), sep='')
  89. step3 = '{}#{}'.format(' '.join(odd_words), ' '.join(even_words))
  90. if step3.strip == '#':
  91. print('COMPRESSION FAILED')
  92. sys.exit()
  93. print('STEP 3: {}'.format(step3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement