-1

My entire code is:

import itertools as it
import numpy as np
import scipy
from scipy import special
for q in [29, 37, 53, 61]:
    p = int((q-1)/4)
    d0 = [2**(4*i) % q for i in range(p)]
    d2 = [2**(4*i + 2) % q for i in range(p)]
    c2 = list(it.combinations(d0,2))
    cd = list(it.combinations(d2,p-2))
    s2 = [sum(c2[i]) % q for i in range(len(c2))]
    sd = [sum(cd[i]) % q for i in range(len(cd))]
    a = [i for i,x in enumerate(s2) if x == 1]
    b = [i for i,x in enumerate(sd) if x == 1]
    l = [list(c2[i]) for i in a]
    l1 = [list(cd[i]) for i in b]
    c = [[d0.index(l[i][j]) for j in range(2)] for i in range(len(l))]
    d = [[d2.index(l1[i][j]) for j in range(p-2)] for i in range(len(l1))]
    cp = [[4*c[i][j] for j in range(2)] for i in range(len(c))]
    dp = [[4*d[i][j]+2 for j in range(p-2)] for i in range(len(d))]
    dps = [set(x) for x in dp]
    dpp = [4*i+2 %q for i in range(p)]
    cop_dpp = []
    for i in range(len(dp)):
        cop_dpp.append(dpp)
    cop_dpps = [set(x) for x in cop_dpp]
    diff = [cop_dpps[i] - dps[i] for i in range(len(dp))]
    diffl = [list(x) for x in diff]
    e = []
    for i in range(len(cp)):
        for o in range(len(cp)):
            x = cp[i] + diffl[o]
            e.append(x)
    f = []
    for k in range(1):
        for l in range(1):
            x = e[k] + e[l]
            f.append(x)
print(q,cp)
print(q, diffl)
print(q,e)
print(q,f)

The error it gives is:

f = []
    ^
IndentationError: unindent does not match any outer indentation level

I have tried moving f = [] every where. Tabbing it in different places in the code (along with the for-loop it depends on) but obtain the same error. Wrote a simple piece of code:

a = [[1,2,3]]
b = [[3,4,5]]
e = []
for i in range(len(a)):
    for o in range(len(b)):
        x = a[i] + b[o]
        e.append(x)
f = []
for k in range(len(e)):
    for l in range(len(e)):
        x = e[k] + e[l]
        f.append(x)
print(e)
print(f)    

which ran fine. I have used tabs for every line of code. Any help would be much appreciated. Thank you in advance!

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
  • 1
    You probably have tabs and spaces mixed somewhere, which confuses Python. – Carcigenicate Jun 06 '18 at 15:18
  • Try having your editor replace every tab with spaces, and see where the indentation doesn't match up. – khelwood Jun 06 '18 at 15:22
  • I am so sorry. It was the TextEditor I was using. Ridiculous. TextMate is garbage. I am sorry for another one of these posts! – Michael Keogh Jun 06 '18 at 15:27
  • What was garbage about it? Is it possible to record something useful here that will help someone having the same problem with TextMate? – Nicholas James Bailey Jun 06 '18 at 15:35
  • See https://stackoverflow.com/q/1024435/1531971 –  Jun 06 '18 at 16:31
  • I am sorry. I called it garbage out of pure frustration. I am very inexperienced with programming in general. I spent way more time trying to figure out the indentation problem than I should of. Hence my frustration. I was using a TextEdit (on mac) to write my code. I decided that I would use TextMate when I started writing the line 'f = []'. And for some reason it started playing with my spacing. When I went back TextEdit I noticed the problem immediately. For some reason it was not showing up on my TextMate was extremely frustrating. – Michael Keogh Jun 06 '18 at 16:52
  • try using sublime or atom. Sublime makes it very easy to replace tabs with spaces or spaces with tabs. – Matthew Ciaramitaro Jun 06 '18 at 17:28
  • Thank you for the suggestion. I downloaded Atom and I got the exact same problem again. I opened my file up in Atom, ran it and got an indent error. Looked at the exact same code in TextEdit and notice the indent error right away (it was clearly misaligned). I have no idea what is happening. I only use tab for indentations. – Michael Keogh Jun 06 '18 at 20:27

1 Answers1

1

Find the setting in your text editor or IDE that allows you to see whitespace - this will help you to see the difference between tabs and spaces in your code. As someone said in the comments, if you have a mixture (which will occur for example when the default in your text editor is different from what you instinctively do), python won't be able to work out your indentation.