58 lines
1.0 KiB
Python
58 lines
1.0 KiB
Python
|
def main():
|
||
|
print(evenThenOdd('abcd'))
|
||
|
print(removeAdjacentDuplicates('mississipi'))
|
||
|
print(reapeatNumTimes(4))
|
||
|
print(positionOfFirstLargest([1, 624, 123, 34, 12]))
|
||
|
|
||
|
def evenThenOdd(string):
|
||
|
even = ''
|
||
|
odd = ''
|
||
|
index = 0
|
||
|
for char in string:
|
||
|
if index % 2 == 0:
|
||
|
even += char
|
||
|
else:
|
||
|
odd += char
|
||
|
index += 1
|
||
|
return even + odd
|
||
|
|
||
|
|
||
|
def removeAdjacentDuplicates(s):
|
||
|
s = str(s)
|
||
|
newS = ''
|
||
|
lastChar = 'a' if s[0] != 'a' else 'b'
|
||
|
for char in s:
|
||
|
if char != lastChar:
|
||
|
newS += char
|
||
|
lastChar = char
|
||
|
return newS
|
||
|
|
||
|
|
||
|
def reapeatNumTimes(n):
|
||
|
lst = []
|
||
|
for i in range(1,n+1):
|
||
|
for j in range(i):
|
||
|
lst.append(i)
|
||
|
return lst
|
||
|
|
||
|
|
||
|
# <!-- -->
|
||
|
def positionOfFirstLargest(arr):
|
||
|
mx = maxArray(arr)
|
||
|
index = 0
|
||
|
for a in arr:
|
||
|
if a == mx:
|
||
|
return index
|
||
|
index += 1
|
||
|
|
||
|
def maxArray(arr):
|
||
|
mx = 0
|
||
|
for a in arr:
|
||
|
if a > mx:
|
||
|
mx = a
|
||
|
return mx
|
||
|
# <!-- -->
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|