0

I have an output like this :

['', '', '', 'Color', 'Yellow', 'RBC/hpf', '4-6', 'Appereance', 'Semi', 'Turbid', 'WBC/hpf', '2-3', 'Specific', 'Gravity', '1014', 'Epithelialcells/Lpf', '1-2', 'PH', '7', 'Bacteria', '(Few)', 'Protein', 'Pos(+)', 'Casts', 'Negative', 'Glucose', 'Negative', 'Mucous', '(Few)', 'Keton', 'Negative', 'Blood', 'Pos(+)', 'Bilirubin', 'Negative', 'Urobilinogen', 'Negative']

Then I wanna remove '' from the list and finally I have some Continuous letters in list and how can I put them togrther? , like : semi Turbid (in the list)

Thanks :)

sushanth
  • 8,275
  • 3
  • 17
  • 28

3 Answers3

1

To remove '' from the list you can use

list2 = [i for i in list1 if i != '']

Then if you want to create a string from the list you can use

" ".join(list2)
0

You can use this:

b = [x for x in a if len(x)>1]

or this:

b = [x for x in a if x != '']

That removes the '' sign in the second one and in the first one discards everything that has a length of less than 1.

If you want to join strings you can use .join() method, for example:

a = ['abc', 'def']
''.join(a)
'abcdef'

'-'.join(a)
'abc-def'
Jonas Palačionis
  • 4,591
  • 4
  • 22
  • 55
0

the list class has a remove method used like this: list.remove() to remove empty list items just type list_name.remove('')