Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- string = input()
- if len(string) == 0:
- print('COMPRESSION FAILED')
- sys.exit()
- # step1 = []
- step1 = ''
- # for word in string.split(' '): // I recommend you don't split the string immediately
- for i in range(len(string)): # For each character in string
- # if '12' in word:
- # twelve = ''
- # f = word.find('12')
- # twelve += (list(word).pop(f) + list(word).pop(f+1))
- # step1.append(twelve)
- # The instructions state that you should just include the string '12' and all alpha characters
- if string[i].isalpha() or string[i] == ' ':
- step1 += string[i] # add character to step1 if it's alphanumeric
- else:
- if 0 < i - 1 < i + 1 < len(string): # if it isn't the end or beginning of the string
- # also prevents IndexError from occuring
- # if it's the substring '12'
- if string[i] == '1' and string[i + 1] == '2': # current string is '1', next string is '2'
- step1 += string[i]
- elif string[i] == '2' and string[i - 1] == '1': # current string is '2', prev string is '1'
- step1 += string[i]
- # else:
- # alpha = ''
- # for c in word:
- # if c.isalpha():
- # alpha += c
- # if len(alpha) > 0:
- # step1.append(alpha)
- if len(step1) == 0:
- print('COMPRESSION FAILED')
- sys.exit()
- # print('STEP 1: ',' '.join(step1), sep='')
- print('STEP 1: {}'.format(step1))
- # step1 = ' '.join(step1) # since step1 is a string
- step2 = ''
- for char in step1:
- # if char.isalpha(): # you can lowercase numbers, don't worry
- # if char in 'aeiouAEIOU':
- if char.lower() in 'aeiou': # more efficient
- step2 += char.upper()
- else:
- step2 += char.lower()
- # else:
- # step2 += char
- print('STEP 2: ', step2, sep='')
- # step3a = []
- # step3b = []
- # Stick to proper naming conventions
- odd_words = []
- even_words = []
- step2 = step2.split(' ')
- # for word in step2:
- for i in range(len(step2)): # easier
- # if step2.index(word) % 2 == 0:
- word = step2[i]
- if i % 2 == 0:
- oddw = ''
- # for c in list(word):
- for j in range(len(word)):
- # if list(word).index(c) % 2 == 0:
- if j % 2 == 0:
- # oddw += c
- oddw += word[j]
- # step3a.append(oddw)
- odd_words.append(oddw)
- else:
- # step3b.append(word[len(word)//2:])
- even_words.append(word[len(word)//2:])
- # print('STEP 3: ', ' '.join(step3a), '#', ' '.join(step3b), sep='')
- print('STEP 3: {}#{}'.format(' '.join(odd_words), ' '.join(even_words)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement