Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hxueh
Last active January 8, 2019 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hxueh/24b4478c58eaa0d38ee62d2f89ad8311 to your computer and use it in GitHub Desktop.
Save hxueh/24b4478c58eaa0d38ee62d2f89ad8311 to your computer and use it in GitHub Desktop.
matrix.html in CS50 2017 Pset6 Similarities (more comfortable)
<table class="table table-sm">
<thead>
<tr>
<!--There are three empty cell in the first header-->
<th></th>
<th></th>
<th></th>
<!--s2 is the string2, according to application.py-->
{% for character in s2 %}
<th>{{character}}</th>
{% endfor %}
</tr>
<tr>
<!--Two empty cell in the second header-->
<th></th>
<th></th>
{% for i in range((s2)|length + 1) %}
<th>{{i}}</th>
{% endfor %}
</tr>
</thead>
<tbody>
<tr>
<th></th>
<th>0</th>
{% for i in matrix[0] %}
<th>{{i[0]}}</th>
{% endfor %}
</tr>
{% for t in range(s1|length) %}
<tr>
<th>{{s1[t]}}</th>
<th>{{t + 1}}</th>
{% for i in matrix[t + 1] %}
<td>{{ i[0] }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
@eboisseau
Copy link

you mean <td>{{ i[0] }}</td> on line 35, don't you?

@hxueh
Copy link
Author

hxueh commented Apr 5, 2018

@eboisseau Oh, yeah! Just typos.

@prateek-parashar
Copy link

Hey there, if possible, could you please give an explanation as to how you accessed the elements of the matrix in line 34 and 35?
My doubt pertains to the fact of how this indexing valid, since the matrix we generated and returned in the back end is a matrix of tuples. I generated as a list of lists, and in general, to access the number I used the syntax like - matrix[i][j][0] to get the number at that particular case, but here, the code successfully returns that value with just one indexing which is perplexing to me.
An explanation would be appreciated

@Destroyer9000
Copy link

I'm not 100% certain but I think you have to include helpers.py, I wrote it like this: "{% include "helpers.py" %}" but I can't check if it works because of other errors

@jainilvachhani
Copy link

Can you explain why you are using
range((s2)|length + 1)
Specifically what is length?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment