# Learn Recursion by Solving the Tower of Hanoi Puzzle - Step 3

##Hello I don’t know if anyone pass this level of the new python module.
#The task is to genrate and assign value (3 - 1) to rods[‘A’] using range().
#Try list(range(3,0,-1)
#used list comprehension i for i in range(3,0,-1).

# tried both within the dictionary and outside of it. And both output the expected result but still I’m stuck in the task.

``````
/* User Editable Region */

rods = {
'A': [],
'B': [],
'C': []
}
#my last tried code below
rods['A'] = list(range(3, 0, -1))
print(rods)

/* User Editable Region */

``````

User Agent is: `Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36`

### Challenge Information:

Learn Recursion by Solving the Tower of Hanoi Puzzle - Step 3

change the line that gives value to the `A` rod in the dictionary

remove `list` and `print()` function

1 Like

What line, is it with the dictionary rods, if that I have tried

``````rods {
'A' : list(range(3,0,-1)),
...
}
``````

And also

``````rods {
'A' : [i for i in range(3,0,-1)],
...
}
``````

Still not working

only `range` in this step

1 Like

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Wow it worked
See the code

``````rods{
'A': range(3,0,-1),
...
}
``````
1 Like

or what it’s worth, the assignment here after the dict definition will also pass the test (need to remove the `list()` as @aaronvincent6411 mentioned)

``````x = range(3, 0, -1)
print(x)
>> range(3, 0, -1)

print(x[0])
>> 3

x = list(range(3, 0, -1))
print(x)
>>[3, 2, 1]

print(x[0])
>>0
``````

Assigning `range()` directly creates a `range` object (generator?) whereas using `list()` creates an actual list.

In usage, it’s basically the same, but the `range()` will save resources by only producing the numbers on demand (lazily)

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