Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/Amazing solutions for the attributeerror: 'list' object has no attribute 'lower' error
Next
Answered
Molly Roy
  • 16
Molly Roy
Asked: May 18, 20222022-05-18T20:50:40+00:00 2022-05-18T20:50:40+00:00In: python

Amazing solutions for the attributeerror: ‘list’ object has no attribute ‘lower’ error

  • 16

. Advertisement .

..3..

. Advertisement .

..4..

I am tired of fixing the problem: attributeerror: ‘list’ object has no attribute ‘lower’ in the python; even if I get the reference from another forum, it still returns an error:

AttributeErrorTraceback (most recent call last)
 <ipython-input-84-33bbe380449e> in <module>()
  1 data = [line.strip() for line in open("C:\corpus\TermList.txt", 'r')]
 ----> 2 texts = [[word for word in data.lower().split()] for word in data]
  3 
 AttributeError: 'list' object has no attribute 'lower'

To identify the problem, I will show you the detail here:

data = [line.strip() for line in open("C:\corpus\TermList.txt", 'r')]
 texts = [[word for word in data.lower().split()] for word in data]

How do I do that? Could you support me in improving this problem?

list object has no attribute lower
  • 3 3 Answers
  • 141 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

3 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    dttutoria Expert
    2022-06-29T11:02:53+00:00Added an answer on June 29, 2022 at 11:02 am

    The cause: You attempted to use lower() on a list of data but lower() only works on strings.

    Solution: 

    Try this to fix the problem: attributeerror: ‘list’ object has no attribute ‘lower’:

    data = [line.strip() for line in open("C:\corpus\TermList.txt", 'r')] 
    texts = [[word.lower() for word in text.split()] for text in data]
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. gilbertcane
    2022-10-18T06:21:30+00:00Added an answer on October 18, 2022 at 6:21 am

    Python lists cannot be divided into separate lists based on characters that appear in the values of a list. This is unlike strings which values can be separated into a list. The AttributeError is an exception thrown when an object does not have the attribute you tried to access. The ‘list’ object has no attribute ‘split’ and you’re trying to call python split() function on the whole list of lines, and you can’t split a list of strings, only a string. So, you need to split each line, not the whole thing.

    To solve the above problem, you need to iterate over the strings in the list to get individual strings; then, you can call the split() function.

     

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  3. Alice Besson
    2022-05-25T21:10:16+00:00Added an answer on May 25, 2022 at 9:10 pm

    You will need

    texts = [[word.lower() for word in line.split()] for line in data]

    This code will generate a list with lowercase words ([word.lower() for word in line.split()]) for every line (data). Each str line will have a sequence of space separated words.line.split() will convert this sequence into a list. word.lower() will change each word to lowercase.

    • 18
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.