[Tutor] longest common substring
lina.lastname at gmail.com
Sat Nov 12 15:48:16 CET 2011
On Sat, Nov 12, 2011 at 9:22 PM, Dave Angel <d at davea.name> wrote:
> On 11/12/2011 03:54 AM, lina wrote:
>> The one I tried :
>> if longest>= 2:
>> if sublist not in sublists:
>> the $ python3 CommonSublists.py
>> atom-pair_1.txt atom-pair_2.txt
>> Traceback (most recent call last):
>> File "CommonSublists.py", line 47, in<module>
>> File "CommonSublists.py", line 24, in CommonSublist
>> AttributeError: 'NoneType' object has no attribute 'append'
>> in local domain I set the result=
>> I don't know why it complains its NoneType, since the "result" is
>> nearly the same as "sublists".
> Assuming this snippet is part of a loop, I see the problem:
> result = result.append(sublist)
> list.append() returns none. It modifies the list object in place, but it
> doesn't return anything. So that statement modifies the result object,
> appending the sublist to it, then it sets it to None. The second time
> around you see that error.
I am sorry. haha ... still lack of understanding above sentence.
['3', '5', '7', '8', '9']
[['3', '5', '7', '8', '9']]
Sorry and thanks, best regards,
> In general, most methods in the standard library either modify the object
> they're working on, OR they return something. The append method is in the
> first category.
More information about the Tutor