Python add a single string to a list

133 views Asked by At

I have the following Problem:

I have a list of items, in which the first Word represents the type of something e. .g:

Wall DXU76542 Table Uxitr Wall rT4 Mobile Tr2 . . .

I would like to create another list analogous to this list, extract the single letters at the beginning of every row and add them to the corresponding row of the second list until the space letter " " appears. Thus I can create a second list out of the first list with only types of the items. Here is part of the code in Python (the list: "elements" is a flat list):

for Element in elements:
        list1.Add(Element.Name)

list2=[]
list2.append([])
for i in xrange(0,len(list1)):
    for j in xrange(0,len(list1[i])):
        l=0
        while not (list1[i][l]==" "):
            list2[i][j].append(list1[i][l])
            l = l+1
Output=list2

Does anybody have any idea, why I get the error:

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

Thank you.

0

There are 0 answers