0

I currently have a list

outcomes = [('A','B','C','A.B','A.C','B.C','A.B.C')]

and I am trying to loop over it. If one of the "name" in the list contains a A, then I want to create another list called column_names with that name in it. For instance, if I am looking for As, my returning list would be:

column_names = ['A','A.B','A.C',A.B.C']

I have the following code:

column_names = []
for name in outcomes:
    if 'A' in name:
        column_names = column_names.append(name)

but it returns:

AttributeError: 'NoneType' object has no attribute 'append'

I checked and both column_names and outcomes are lists so I dont understand why.

ayhan
  • 70,170
  • 20
  • 182
  • 203
Dine
  • 47
  • 8

1 Answers1

0
my_list=list()
 for i in outcomes:
    for j in i:
        if   j.count('A') == 1: 
            my_list.append(j)

output:

['A', 'A.B', 'A.C', 'A.B.C'] 

in your code you used column_names = column_names.append(name) you must use column_names.append(name) instead

keyvan vafaee
  • 464
  • 4
  • 15