Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

AttributeError: 'NoneType' object has no attribute 'title', how can I resolve this error

I want to add names in capital to group_list from names list but I get AttributeError: ‘NoneType’ what am I doing wrong? and also I want to know how many names are added to group_list. I hope someone can help me out.

group_list = ['Jhon', 'James', 'Rita', 'Ruth']
names = ['issah', 'ruth', 'kane']
for name in names:
    if name.title() not in group_list:
        group_list.append(name).title()

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

number_of_names_added = 0
group_list = ['Jhon', 'James', 'Rita', 'Ruth']
names = ['issah', 'ruth', 'kane']
for name in names:
    if name.title() not in group_list:
        group_list.append(name.title())  # Correction here
        number_of_names_added += 1
print(f'{number_of_names_added} name(s) added to group_list')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading