Hello,

Below a part of my code. The part 'for index in range(len(regels))' works but doesn't go through all of the lists in 'regels'. 'regels' is a nested list.

for row in inputReader:

        regels = ['Auto','Brandstof auto',' tinq ',' shell ',' tank s ',' dap ',' slump oil ','q8 ','brand oil',' bp lemmer '],
        ['Huishouden','Boodschappen',' poiesz ',' spar ','super de boer','c 1000',' aldi ',' albert heyn ','breimer ',' keurslager',' bakkerij ']
        
        for index in range(len(regels)):
            totaal = regels[index]; bestemming = totaal[:2]; zoekterm = totaal[2:]
            for i in range(len(zoekterm)):
                if( zoekterm[i] in str(row[7]).lower()):
                    in_rubriek = bestemming[0]; in_grootboek = bestemming[1]


        uit_row = [ uit_datum, uit_reknr, uit_begunstigde, uit_tegenrek, uit_bedrag, uit_code, uit_rubriek, uit_grootboek , uit_omschrijving]
        outputWriter.writerow(uit_row)

It must be something simple, but I don't see it. Any help would be nice.

Thanks in advance

Bauke

I don't think that you have there a nested list.

regels = ['Auto','Brandstof auto',' tinq ',' shell ',' tank s ',' dap ',' slump oil ','q8 ','brand oil',' bp lemmer '],
        ['Huishouden','Boodschappen',' poiesz ',' spar ','super de boer','c 1000',' aldi ',' albert heyn ','breimer ',' keurslager',' bakkerij ']

Here regels is a tuple.
Here, let me show you something.

a = ['as', 'dsd', 'dfd'], ['dfs', 'wew', 'das']
l = ['3']
print a + l

"""Output:

Traceback (most recent call last):
  File "*:\*****\Workspace eclipse\****\**\as.py", line 8, in <module>
    print a + l
TypeError: can only concatenate tuple (not "list") to tuple
"""

This piece of code, as your regels, shows the printing of a tuple and a list, which is impossible.
but

a = [['as', 'dsd', 'dfd'], ['dfs', 'wew', 'das']]
l = ['3']
print a + l
"""
Output:
[['as', 'dsd', 'dfd'], ['dfs', 'wew', 'das'], '3']
"""

In your case, you don't have nested lists.
The only difference between these 2 pieces of code is that in 1, a is a tuple, and in the 2nd, a is a nested list with [].
Perhaps you should try with this and then reply. Having a part of your code makes it impossible for me to determine if that's the cause of the problem.

Thanks! After adding [] everything works fine.

Bauke

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.