P
P
ParseMeBaby2021-06-29 17:40:29
Python
ParseMeBaby, 2021-06-29 17:40:29

Why are my Python lists NoneType?

I have an excel code that needs to convert strings to lists by changing the strings to all combinations of words in the string. When I tried to assemble the received lists back into a string, I ran into the problem that my received lists are actually not lists, but NoneType. How to collect in these elements in the correct lists? (conditional future lines are separated by an empty list[] )
Example:

output:
['second', 'red']
['red', 'second']
['second']
['red']
[]

desired output:
second red, red second, second, red #(строка)

import pandas as pd   # pip install pandas
def gencombs(comb, lst, idx):
    if idx >= len(lst):
        print(comb)
    else:
        for i in range(len(comb),-1, -1):
            gencombs(comb[:i] + [lst[idx]] + comb[i:], lst, idx + 1)
        gencombs(comb, lst, idx + 1)

df = pd.read_excel(r'C:\Users\Iclub\Desktop\parserTest.xls', sheet_name='Sheet1')
var1 = df['first (A1)'].tolist() 

for i in var1: 
    last = i.split()
    momo = gencombs([], last, 0)
         print(momo)

output:

['first', 'blue']
['blue', 'first']
['first']
['blue']
[]
['second', 'red']
['red', 'second']
['second']
['red']
[]
['third', 'white']
['white', 'third']
['third']
['white']
[]

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question