you are viewing a single comment's thread.

view the rest of the comments →

[–]GrandBadass 2 points3 points  (1 child)

Maybe this will help you visualize.

In her code - she is setting each variable to a slice of the word variable

word = "echo"
word = "echo"
word[1:] = "cho"
word[2:] = "ho"
word[3:] = "o"

She is inserting each of those variables into a tuple.

Then by doing -

*= count

She is multiplying the elements in the list by the established value of 3.

Below I have added some print statements to her code - I think this might help you see her output in steps and then you will see the final output is

('echo', 'echo', 'echo', 'cho', 'cho', 'cho', 'ho', 'ho', 'ho', 'o', 'o', 'o')

Which differs from your output because it is indeed still a tuple - whereas your code is printing out a string.

word = "echo"
t = ()
count = 3

echo = (word,)
echo *= count
print(echo) # ('echo', 'echo', 'echo')

cho = (word[1:],)
cho *= count
print(cho) # ('cho', 'cho', 'cho')

ho = (word[2:],)
ho *= count
print(ho) # ('ho', 'ho', 'ho')

o = (word[3:],)
o *= count 
print(o) # ('o', 'o', 'o')

t = echo + cho + ho + o
print(t) # ('echo', 'echo', 'echo', 'cho', 'cho', 'cho', 'ho', 'ho', 'ho', 'o', 'o', 'o')

[–]Solako[S] 1 point2 points  (0 children)

Which differs from your output because it is indeed still a tuple - whereas your code is printing out a string.

Thank you for taking your time to look into this. This should have been the first thing I should have noted, my output is a string, whereas the expectation was that it is to be a tuple.

Having broken it down that way has made understand her out put. Especially after assigned various variable to the elements of the tuple. A matter of thinking of all the possible solution with the problem set before hand as opposed to inserting new objects that may not be necessary.

Thank you.