Note that there are some explanatory texts on larger screens.

plurals
  1. POFinding an exact position of a smaller list inside a list (python)
    primarykey
    data
    text
    <p>So i Have a list which is something like this:</p> <pre><code>list=[10.0, 10.0, 10.0, 9.9, 9.9, 9.9, 10.0, 9.9, 10.0, 10.0, 10.0, 10.0, 9.9, 9.9, 9.9, 9.9, 9.9, 9.9, 10.0, 10.0, 10.0, 10.2, 10.0, 9.9, 9.9, 9.9, 9.9, 10.0, 10.2, 10.0, 9.9, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.1, 10.0, 10.0, 10.0, 10.0, 10.0, 10.1, 10.1, 10.1, 10.1, 10.1, 10.1, 10.1, 10.1, 10.1, 10.1, 10.1, 10.2, 10.2, 10.2, 10.2, 10.2, 10.2, 10.2, 10.2, 10.2, 10.3, 10.3, 10.2, 10.2, 10.3, 10.3, 10.2, 10.2, 10.2, 10.2, 10.2, 10.2, 10.3, 10.2, 10.5, 10.9, 10.5, 10.3, 10.3, 10.3, 10.2, 10.2, 10.2, 10.2, 10.1, 10.1, 10.1, 10.1, 10.1, 10.1, 10.1, 10.1, 10.4, 10.7, 10.3, 10.2, 10.1, 10.1, 10.0, 10.0, 10.0, 10.0, 10.0, 9.9, 9.9, 9.9, 10.0, 9.9, 9.9, 9.9, 10.1, 9.9, 9.9, 9.8, 9.8, 9.8, 9.8, 9.8, 9.8, 9.8, 9.8, 9.8, 9.8, 9.8, 9.8, 9.8, 9.7, 9.8, 9.8, 9.7, 9.7, 9.7, 9.7, 9.7, 9.7, 9.6, 9.7] </code></pre> <p>And then i also has a sublist which looks something like this:</p> <p><code>sublist=[9.9, 9.9, 9.8, 9.8, 9.8, 9.8, 9.8, 9.8, 9.8, 9.8]</code></p> <p>now what I need to do with this smaller list, is that I have to find where this is located in the main list. So in this case the result should be something like this: index=119 (I might be off with +/-1)</p> <p>I've been trying to do this all day... And didnt find anything on the web... I have a few ideas:</p> <p>1) I find the first item of the sublist on the list....which in this case would be 4, so i check the next number which is also correct then the next which will be wrong and it would send it to find another 9.9 in the remaining list[4:] and do the same loop again...until an exact match is found</p> <p>2) Then another idea is to somehow use strings str(list)[1:-1].find(str(sublist)[1:-1]), which in this case would give the answer of 687...</p> <p>Problem with these ideas is that they seem to be long and sloppy and also I haven't been able to make these ideas work...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload