Skip to content

Instantly share code, notes, and snippets.

@Pierian-Data
Created March 1, 2018 17:23
Show Gist options
  • Save Pierian-Data/5767f49f825dbc9f9bf1357b2152b010 to your computer and use it in GitHub Desktop.
Save Pierian-Data/5767f49f825dbc9f9bf1357b2152b010 to your computer and use it in GitHub Desktop.
def myfunc(x):
out = []
for i in range(len(x)):
if i%2==0:
out.append(x[i].lower())
else:
out.append(x[i].upper())
return ''.join(out)
@AbhijeetRaaj
Copy link

A another approach that I have tried using args:

def myfunc(*args):
mystr = str(args)
new_list = list(mystr)
length = len(new_list)
order_list = []
final = ''
even = (mystr[0:length:2].lower())
l_even = len(even) - 1
odd = (mystr[1:length:2].upper())
l_odd = len(odd) - 1

while length !=0:
    if length%2 != 0:
        order_list.append(even[l_even])
        l_even = l_even - 1
    else:
        order_list.append(odd[l_odd])
        l_odd = l_odd - 1
    length = length -1
order_list.reverse()
for i in order_list:
    final = final + i
return final

this is good to add any number of arguments that can be fit for this usecase

image

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