Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify index error #250

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

modify index error #250

wants to merge 2 commits into from

Conversation

Case3y
Copy link

@Case3y Case3y commented Dec 2, 2022

An error occurred in the indexing of the list(dp_table): IndexError: list assignment index out of range
modify its index

@TylerWelch
Copy link

Instead of switching the variables, it cant degradate the index on the other side of the assignment it should be j-1 i-1 not i-1 i-1. That is not a index location.

@Case3y
Copy link
Author

Case3y commented Dec 16, 2022

Instead of switching the variables, it cant degradate the index on the other side of the assignment it should be j-1 i-1 not i-1 i-1. That is not a index location.

yes, I forget it! I think the final correct code is as follows:

dp_table_blue = ["b", "l", "u", "e"]
dp_table_clues = ["c", "l", "u", "e", "s"]
dp_table = [[0 for i in range(len(dp_table_blue))] for i in range(len(dp_table_clues))]
print(dp_table)  

for i in range(0, len(dp_table_clues)):
    for j in range(0, len(dp_table_blue)):
        if dp_table_clues[i] == dp_table_blue[j]:
            dp_table[i][j] = dp_table[i - 1][j - 1] + 1
        else:
            dp_table[i][j] = 0

print(dp_table)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants