0

I have a list of emails when printed look like this (they look like this because of how the csv file is set up. I can't change that)

enter image description here

The code I have is:

list1=[x.strip().split(',')for x in list1]

but its giving me an error: 'list' object has no attribute 'strip'

I have also tried:

list1[filt_count]=list1[filt_count].Trim()

but it gives an error: 'list' object has no attribute 'Trim'

Expected Outcome: Now obviously these are example emails and the list is gonna be much larger (over 500 emails all said and done) enter image description here

rmcknst2
  • 195
  • 1
  • 2
  • 11
  • I already viewed that thread and .trim() also gives me an error @sheldore – rmcknst2 Jun 07 '19 at 22:52
  • 1
    Marked as duplicate of a C# question? This is tagged python... And the problem here is that he's dealing with a list of lists, which he does not seem to be aware of. – paul Jun 07 '19 at 22:54
  • 1
    Duplicate here : https://stackoverflow.com/questions/13071053/python-removing-whitespace-from-string-in-a-list – Sheldore Jun 07 '19 at 23:02

2 Answers2

3

First: please avoid posting images. It's much easier to reproduce what you do when we can cut and paste your code.

1) What you have is a list of lists. This needs to be take account of in the comprehension. 2) x.strip().split(',') does not make sense, as you are not dealing with a comma separated string

[[x.strip() for x in l] for l in list1]
paul
  • 408
  • 2
  • 8
0

You have a list of lists and you are not really using csv to it's extent. What you want doesn't require you to use x.strip().split(",") so it is unnecessary to have. The correct answer would be [[x.strip() for x in y] for y in list1]