# Unit 10: List Slicing

#1

In this exercise, there is a 'garbled' message, which has two steps that need to be carried out in order to complete.

When I enter my code, it comes up with the following message "Make sure to use list slicing and a negative stride in your answer!"

I have tried two different ways (both using list slicing and a negative stride), and both result in the same message.

Any help would be much appreciated.

``````Attempt 1:
garbled = "!XeXgXaXsXsXeXmX XtXeXrXcXeXsX XeXhXtX XmXaX XI"

first = []
for x in garbled:
first.append(x)

message = "".join(first[::-1])
#print first_reverse
string = ""
for y in message:
if y == 'X':
continue
else:
string += y
print string

Attempt 2:
garbled = "!XeXgXaXsXsXeXmX XtXeXrXcXeXsX XeXhXtX XmXaX XI"

message_reverse = []
for x in garbled:
message_reverse.append(x)

message = message_reverse[::-1]
#print message

for x in message:
if x == 'X':
message.remove(x)

message = "".join(message)

print str(message)``````

#2

@cbr_boy: Your code sure prints correctly but perhaps not exactly what the exercise is telling you.
If I'm not wrong, in case I am wrong I apologize, this is the exercise (?) and according to that, you were supposed to use list slicing and the negative strider.

All cool! You are, in fact using the negative strider but not exactly list slicing.
The negative strider will just "bring" back your string backwards (or even list) but won't really slice it.
The size of it will still be the same.

Try to slice and later use the neg. stride!

Note: you don't really need all of that but it's a nice idea to get used with using functions

Hope it helps!

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.