-1

I have a list list1 (example) as shown below. It's the result of a function in my code.

Example:

list1 = ['2  String 2'] ['3  string 3'] 

Expected output from the above list is as below:

list1  = ['2  String 2', '3    string 3']

I'm stuck at this point.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • 1
    Your input is a type error. Also: what have you tried, and what exactly is the problem with it? – jonrsharpe Apr 14 '19 at 08:06
  • 1
    I'd say you want to flatten a list of lists – Jean-François Fabre Apr 14 '19 at 08:09
  • 3
    Possible duplicate of [How to make a flat list out of list of lists](https://stackoverflow.com/questions/952914/how-to-make-a-flat-list-out-of-list-of-lists) – Ora Aff Apr 14 '19 at 08:11
  • Hi, I am extracting the information from a pdf file. There is a list if strings in 2 pages. '2 String 2' is at the end of the first page and '3 string 3' is at the starting of 2nd page. I tried splitlines() function which generated this output ['2 String 2'] ['3 string 3'] . Trying to convert it into single list so that I can use it ahead. – Sumit Pahwa Apr 14 '19 at 08:11

1 Answers1

1

Assuming your list looks like this (and not as in your example):

list1 = [['2  String 2'], ['3  string 3']]

Then simply:

list1 = [i[0] for i in list1]
  • Hi, I am extracting the information from a pdf file. There is a list of strings in 2 pages. '2 String 2' is at the end of the first page and '3 string 3' is at the starting of 2nd page. I tried splitlines() function which generated this output ['2 String 2'] ['3 string 3'] . Problem is the output of the splitlines. If input is like '[['2 String 2'], ['3 string 3']]' as you take in the example. Then it's easy to go ahead. – Sumit Pahwa Apr 14 '19 at 08:17
  • Can you tell me the output of `print(type(list1))` and `print(type(list1[0]))`? –  Apr 14 '19 at 08:21
  • Output for print(type(list1)) is : Output for print(type(list1[0])) is : – Sumit Pahwa Apr 14 '19 at 08:22
  • Then you have nested lists and my answer should work. What is your output from my answer? –  Apr 14 '19 at 08:24