M HYPE SPLASH
// updates

Python - TypeError: 'list' object is not callable [closed]

By Emma Payne

I'm trying to write a text file that has a list of rearranged alphabets so that each begins with a different character. The first letter is moved to the end, repeat.

 alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] # generate 26 alpabets without typing all def alpha_gen(alphabet,a_list): x = 0 while x < 26: alphabet += [alphabet.pop(0)] key = alphabet(0) written = str(key) + ' : ' + str(alphabet) + '\n' a_list.write(written) x += 1 def main(): a_list = open('alpabet_list.txt', 'w') alpha_gen(alphabet, a_list) a_list.close() if __name__ == '__main__': main()

But I get this error:

 File "vigenere_cipher.py", line 13, in alpha_gen key = alphabet(0) TypeError: 'list' object is not callable
1

1 Answer

File "vigenere_cipher.py", line 13, in alpha_gen
key = alphabet(0)
TypeError: 'list' object is not callable

In Python, () indicate that you want to call (execute) some function. What you are doing in line 13 with alphabet(0) is trying to call alphabet which is a list, not a function. Change it to alphabet[0] to access first element of alphabet list.