4

Not knowing this problem (regular CS50 without x?), I can tell you what the code does. results = list(set(alist) & set(blist)) turns the intersection of those two sets into a list. return [results] returns a new list with one element, the list of strings. Your later code lets me assume you want a list of strings, not a list containing exactly one ...


2

See this: https://stackoverflow.com/questions/30792428/wagner-fischer-algorithm It was the only way I was able to understand the algorithm. Then, once you know what's going on, check this: https://www.youtube.com/watch?v=b6AGUjqIPsA


2

The cost is actually matrix[len(a)][len(b)][0] (as matrix[len(a)][len(b)] is a tuple like (4, Operation.INSERTED). But you are meant to return the matrix (a list of lists of tuples), and the calling code will figure out. edit, to answer questions not clear from the actual question but comments: I assume you watched and understood all the videos on dynamic ...


2

except for the first element, which is supposed to have no operation, but I gave it an Operation.SUBSTITUTED And this is probably the problem, since that operation subtracts 1 from i and j, which means when matrix[0][0] is dealt with, i and j both get set to -1, which will be out of range. Perhaps you should be using None instead of Substituted for the ...


2

In python, when you get a syntax error on an apparently correct line, look to the previous line. How many parenthesis characters in the prior return line? It's odd.


2

Look at your asub and bsub right before returning an answer. (you can use print to see what they are). Looks like they're getting re-defined for each i rather than accumulating a list of all possible options.


2

You have some substrings that are shorter than the others because there are no n characters left at index i. How many substrings of length n can you have in a string of length len(a)? n is part of the formula that goes into the range call.


2

Since it's in a jinja "statment", maybe it's a jinja thing. An internet search for 'jinja length' finds this: length(object) Return the number of items of a sequence or mapping. Aliases: count There are a lot of other results you may find interesting.


2

De acuerdo a las especificaciones: Stored in each element of the matrix should be a tuple, (cost, operation), where cost is an int and operation is an Operation. So what does the line of code mean?. Means that we assign the values of the tuple to two variables but the first of them is ignored, only the second value is of interest to us. Sometimes this ...


2

You could indeed utilise the Python's build-in Set type, although not compulsory, together with its intersection method for the purpose of filtering within all three functions. However, the use of sent_tokenize is imperative as the manual implantation of its equivalent would be bit more complex and is out of scope for the problem set. The outlined ...


2

So I'll look into compare. from helpers import lines, sentences, substrings This line imports the three functions you are meant to implement. helpers.py gets executed, and the content of variables lines, sentences, and substrings are imported into compare's namespace, making them available by their name. Unlike bleep, it's not your job to open the files, ...


1

the TL;DR: is that sent.tokenize() wants you to send it a string of English text, and it will spit back a list of the sentences contained in that long string (aka a list of strings). See here for an accessible overview of the tokenizing functions of NLTK. so if I have a string of text >>> string = "Python is cool. Python is fun. Python is great." ...


1

Jinja, unfortunately, does not support executing arbitrary Python code, such as len(s2) Hence, in order to get the length of a string, the use of a filter is required.


1

score expects your text in files. Are cat and ate text files? Also, to check your operations are correct, you might have to use the flask run web thing. Your way of picking an operation looks overly complicated. Why don't you calculate total cost (including the +1 except for "substituting" same character) before applying min?


1

With your remove, you only remove the first occurrence of the element, and only from one list. Also, changing the iterable you are iterating is bad style, can lead to unexpected or sometimes even undefined behaviour. One approach would be to remove duplicates before you enter the nested loops, which can be achieved in many ways. I used sets, those are ...


1

You can't install modules on the server, but just creating an empty 2D array doesn't require a whole library. A simple list comprehension like matrix = [[None] * width for y in range(height)] would work. I use two concepts here. [None] * width will concatenate the list width times. Beware that this involves a shallow copy, so it would not work for height,...


1

One of your problems lies in the line matrix[x][y] = matrix[x-1][y-1], Operation.SUBSTITUTED the resulting matrix[x][y] would be a tuple with two elements, first being a tuple itself. You want to use only matrix[x-1][y-1][0]. I think you should get the rest, as it seems you are trying to work around this mistake. Write a comment if you need ...


1

I got it. I got confused with the local and global variable of seta = set(x) and setb = set(y)


1

(Assuming this is python ...) Technically, the problem is in the line lista = set(x.append(a[i:i+n])) You append something to a list, and you try to convert the result into a set. However, the result of the append method is None. To get that code technically working, you should split that line up into one line which appends the character to the list, and ...


1

Your matrix needs to have len(a) + 1 rows of len(b) + 1 cells. The final distance is found in matrix[len(a)][len(b)], which does not exist in your current matrix. A cell matrix[row][col] corresponds to the transformation from a[0:row] into b[0:col], upper left cell matrix[0][0] would be empty string "" to "", lower right cell matrix[len(a)][len(b)] would ...


1

The log relies on your associated operations. Maybe you accidentally use strings and not the required enumeration values. You should use Operation.INSERTED if you reached this field by insertion (the field on the left) Operation.DELETED if you reached this by deletion (the field above) Operation.SUBSTITUTED if you reach the field from the field upper ...


1

I had a similar issue. I had my numbers right, but the wrong operations associated. If your value is created by a move to the right, the operation is Operation.INSERTED. If the move goes downwards, Operation.DELETED is the value to use. For diagonal, it's Operation.SUBSTITUTED. Maybe you put something else there (like None for a field other than upper left ...


1

Ok if anyone else has this question, it works just fine with the error, so it appears you can ignore it.


1

You don't mention what the error is, but more than likely it's caused by you returning a list inside a list. If list(s) returns a list, then [list(s)] returns a list containing one list. You should simply return the list.


1

Take a quick look at score.html, don't you notice that at line 6, it already includes matrix.html into the page? Notice that it also includes log.html at line 11? The point that I'm making is that, you don't need to include {% extends "layout.html" %} and {% block body %} with its associated ending tag anymore in matrix.html, in fact, this is what causes ...


1

Just tried with two files, one ending lines with CRLF (\r\n) and one with LF (\n). Comparing the CRLF file to itself will match only on the last line (not ending in CRLF), while the LF file will match itself on all lines. So you most likely have your files uploaded with CP/M-, DOS-, Windows-style CRLF and not Unix-style LF. A text editor like Notepad++ ...


1

You seem to confuse Operation.DELETED and Operation.INSERTED. Operation.DELETED is used when you advance in the source string a (so you change i) without advancing in target string b, i.e. the source character is deleted. Operation.INSERTED is used when you don't advance in a, but only in b. Operation.SUBSTITUTED is used when you advance in both at the ...


1

check50 doesn't check the form. Same for the similarities/more version. There should have been an error message, and I have no idea why there wasn't (other than a generic "you're sending garbage I don't understand"). So I can tell you what you obviously did wrong and hope it fixes the issue. If you open application.py and read function compare, there are ...


1

I think your insertCost is actually your deleteCost and the other way around.


1

You're browsing templates, not pages generated from templates. You need to call flask run in your similarities directory, and point your browser to the URL flask will present. Something like cd ~/workspace/pset6/similarities flask run (path might be different, and server is stopped via Ctrl+C) Umm... you're using the IDE50, right? Flask might require ...


Only top voted, non community-wiki answers of a minimum length are eligible