# Learn Algorithm Design by Building a Shortest Path Algorithm - Step 47

**URL:** <https://forum.freecodecamp.org/t/learn-algorithm-design-by-building-a-shortest-path-algorithm-step-47/687779>\
**Category:** General\
**Tags:** español\
**Created:** [April 29, 2024, 8:58pm UTC](https://forum.freecodecamp.org/t/learn-algorithm-design-by-building-a-shortest-path-algorithm-step-47/687779 "2024-04-29T20:58:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peibowl](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/peibowl/32/361012_2.png) [@Peibowl](https://forum.freecodecamp.org/u/Peibowl)\
**Post date:** [April 29, 2024, 8:58pm UTC](https://forum.freecodecamp.org/t/learn-algorithm-design-by-building-a-shortest-path-algorithm-step-47/687779/1 "2024-04-29T20:58:51Z")

</div>

### Tell us what’s happening:

I have read already a post about this but I am unable to make it work using the slice syntax I have tried almost everything possible (at least in my head) it has to be something simple but I cant find the answer to progress. Please help!

### Your code so far

```py
my_graph = {
    'A': [('B', 3), ('D', 1)],
    'B': [('A', 3), ('C', 4)],
    'C': [('B', 4), ('D', 7)],
    'D': [('A', 1), ('C', 7)]
}

def shortest_path(graph, start):
    unvisited = list(graph)
    distances = {node: 0 if node == start else float('inf') for node in graph}
    paths = {node: [] for node in graph}
    paths[start].append(start)

    while unvisited:
        current = min(unvisited, key=distances.get)
        for node, distance in graph[current]:
            if distance + distances[current] < distances[node]:
                distances[node] = distance + distances[current]

# User Editable Region

                if paths[node] and paths[node][-1] == node:
                    paths[node]=paths[current]

# User Editable Region

                else:
                    paths[node].extend(paths[current])
                paths[node].append(node)
        unvisited.remove(current)

    print(f'Unvisited: {unvisited}\nDistances: {distances}\nPaths: {paths}')

shortest_path(my_graph, 'A')

```

### Your browser information:

El agente de usuario es: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0`

### Challenge Information:

Learn Algorithm Design by Building a Shortest Path Algorithm - Paso 47

> **[freeCodeCamp.org](https://www.freecodecamp.org/espanol/learn/scientific-computing-with-python/learn-algorithm-design-by-building-a-shortest-path-algorithm/step-47)**
>
> Aprende a programar, ¡GRATIS!

---

<div class="post-metadata">

**Author:** ![Teller](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/teller/32/412338_2.png) [@Teller](https://forum.freecodecamp.org/u/Teller)\
**Post date:** [April 30, 2024, 7:04am UTC](https://forum.freecodecamp.org/t/learn-algorithm-design-by-building-a-shortest-path-algorithm-step-47/687779/2 "2024-04-30T07:04:46Z")

</div>

Welcome to the forum @Peibowl

> You should use the slice syntax to assign a copy of paths[current] to the neighbor node path.

Here is an article on [Python Slicing](https://www.freecodecamp.org/news/python-slicing-how-to-slice-an-array/) you may find helpful.

Happy coding

---

<div class="post-metadata">

**Author:** ![Peibowl](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/peibowl/32/361012_2.png) [@Peibowl](https://forum.freecodecamp.org/u/Peibowl)\
**Post date:** [April 30, 2024, 8:37am UTC](https://forum.freecodecamp.org/t/learn-algorithm-design-by-building-a-shortest-path-algorithm-step-47/687779/3 "2024-04-30T08:37:19Z")

</div>

Problem here is I dont know what to slice. The exercise states " Fix that bug by assigning a copy of `paths[current]` to the neighbor node path."  
In case this is not done by paths[node] = paths[current] I don’t really know how to create that copy of paths[current] as intended in the exercise. I am 100% lost here and for as much as I read about slicing I dont reach the solution.

---

<div class="post-metadata">

**Author:** ![Peibowl](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/peibowl/32/361012_2.png) [@Peibowl](https://forum.freecodecamp.org/u/Peibowl)\
**Post date:** [April 30, 2024, 8:49am UTC](https://forum.freecodecamp.org/t/learn-algorithm-design-by-building-a-shortest-path-algorithm-step-47/687779/4 "2024-04-30T08:49:51Z")

</div>

I got it. I really don`'t find the sense of doing what the exercise admitted as valid to keep progressing. I dont really understand why it works that way and not the previous way implemented.

It would be nice if someone with a higher level of expertise in coding could throw some explanation about the difference.

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![Teller](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/teller/32/412338_2.png) [@Teller](https://forum.freecodecamp.org/u/Teller)\
**Post date:** [April 30, 2024, 11:11pm UTC](https://forum.freecodecamp.org/t/learn-algorithm-design-by-building-a-shortest-path-algorithm-step-47/687779/5 "2024-04-30T23:11:49Z")

</div>

Hi @Peibowl

Assigning is a reference to something. If you change the _something_, then you change what the variable is referencing.

> my\_variable = another\_variable

If later you make a change to another\_variable, my\_variable will reference that.

If you reference a copy of the another\_variable, then the original value is still assigned, even if another\_variable is later modified.

Happy coding

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 7, 2025, 2:16pm UTC](https://forum.freecodecamp.org/t/learn-algorithm-design-by-building-a-shortest-path-algorithm-step-47/687779/6 "2025-01-07T14:16:00Z")

</div>

Closed on January 7, 2025, 2:16pm UTC


