I have a list of sentences like so:
['Business World - user unable to log in', 'Cannot Login', 'customer getting no signal message on projector', 'Account - colleague is unable to access account', 'Password reset after interruption'] of about 8000 elements.
I want to convert the above list to lowercase. I tried using the following line:
my_list = [x.lower() for x in my_list]
But that gives the error:
AttributeError: ‘int’ object has no attribute ‘lower’
So I did the following to ensure that all elements are considered as strings:
my_list = [x.lower() for x in str(my_list)]
This returns the lowers case, but breaks down each word into individual characters?
['[',
"'",
'b',
'u',
's',
'i',
'n',
'e',
's',
's',
' ',
'w',
'o',
'r',
'l',
'd',
' ',
'-',
What am I doing wrong?
>Solution :
str(my_list) serializes your list object to a single string object. Iterating over the string yields every single character in this serialization.
What you probably want is to convert each element into a string (apparently there are also numbers in it outside of your sample) and lowercase that.
lower_list = [str(x).lower() for x in my_list]