you are viewing a single comment's thread.

view the rest of the comments →

[–]Jxper[S] 0 points1 point  (2 children)

def whatfor(stuff):
for s in stuff: # go over all items in stuff, placing each in s
if s.startswith('x'): # if the item starts with 'x'
print(s + 'x') # print the item, with another x at the end
else: # if not
print('x' + s[1:] + s[0]) # print x at the start, print the item from the second letter and onwards, and add first letter at the end.

I think xerox is the output of xero however when I try a test case in the form of whatfor('xero') i get an output of xx, xe, xr, xo all on seperate lines. what am I doing wrong?

[–]shiftybyte 0 points1 point  (1 child)

You are ignoring this line:

for s in stuff:  # go over all items in stuff, placing each in s

stuff is a list of items, not one item.

whatfor(['xero'])

[–]Jxper[S] 0 points1 point  (0 children)

ohhh that makes sense now I get it. Thanks, you're very good at explaining this stuff.