title: How do I make a list out of rows from a database using cursor.fetchall with pyodbc?
body: <p>I have a script that works fine on a simple list. It removes some unwanted characters from a list of words, make them match with each other and returns several lists of similar words (with a 0.6 ratio). </p>
  
  <p>But now I need it to work on an Access Database. 
  I thought that if I made a for loop on crsr.fetchall() and put all items into a list ("words"), that could work like it previously did. Unfortunatly it doesn't and I really can't figure it out... </p>
  
  <p>Here's my code : </p>
  
  <pre><code># -*- coding: utf-8 -*-
  import pyodbc
  import re 
  from difflib import SequenceMatcher
  
  [x for x in pyodbc.drivers() if x.startswith('Microsoft Access Driver')]
  
  # Connection to accdb
  
  conn_str = (
      r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
      r'DBQ=C:\\Users\\alice\\Desktop\\lexique3.accdb;'
      )
  cnxn = pyodbc.connect(conn_str)
  crsr = cnxn.cursor()
  
  # Put all words into a list 
  
  crsr.execute('SELECT unites_lexicales FROM Mot;')
  result1 = crsr.fetchall()
  words = []
  for item in result1 :
      words.append[item]
  print(words)
  </code></pre>
  
  <p>At this point, I got an error : </p>
  
  <pre><code>TypeError: 'builtin_function_or_method' object is not subscriptable
  </code></pre>
  
  <p>I tried to iterate with range : </p>
  
  <pre><code>crsr.execute('SELECT unites_lexicales FROM Mot;')
  result = crsr.fetchall()
  words = []
  for i in range(0, len(result)) :
      words.append(result[i])
  print(words)
  </code></pre>
  
  <p>But I got a list of items that looks like this and it's not satisfying at all :</p>
  
  <pre><code>[('anbaglé', ), ('anfoutan', ), ('òrdinè', ), ('alakous', ), ('ayen', ), ('anmè', ), ('antòtiyé', ),...]
  </code></pre>
  
  <p>Here's the rest of the code that worked perfectly on a simple list : </p>
  
  <pre><code>radicals = [] 
  motifp = "^(re|em|dés)" 
  motifs = "(iste|ment|er|ant|able)$" 
  
  for word in words : 
      word = re.sub(motifp, '', word) 
      word = re.sub(motifs, '', word) 
      radicals.append(word) 
  print(radicals) 
  
  ratio = 0.6
  n = len(radicals)
  result = []
  used_js = []
  
  for i in range(n):
      if i in used_js:
          continue
      matches = [words[i]]
      js = (x for x in range(n) if x != i and x not in used_js)
      for j in js:
          if SequenceMatcher(None, radicals[i], radicals[j]).ratio() &gt;= ratio : 
              matches.append(words[j])
              used_js.append(j)
      result.append(matches)
  print(result)
  </code></pre>
  
  <p>Here is the result I got earlier by testing it on a simple list : </p>
  
  <pre><code>[['flore', 'fleur', 'fleuriste'], ['remaniement', 'remanier', 'manier', 'maniable'], ['désaimer', 'aimant', 'aimer'], ['désemmêler', 'emmêler', 'mêler']]
  </code></pre>
  
  <p>I must have gotten the whole cursor section wrong, I really don't understand how that works... Thanks for your help ! </p>