0

I am trying to build a list of string elements using both explicit strings and a range (to avoid typing hundreds of strings). However, when I attempt to convert all elements in the list into individual strings the entire range element (range(115,131) is convert to really long string. Code below.

    list1 = ["100","105","110",range(115,131),"135"]
    print list1
    [str(i) for i in list1]

This ends up returning:

['100', '105', '110', '[115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130]', '135']

I want it to return (all items as a single individual string):

['100', '105', '110', '115', '116', '117', '118', '119', '120', '121', '122', '123', '124', '125', '126', '127', '128', '129', '130', '135']

K.Jolly
  • 25
  • 5
  • Check this as well: [Flatten (an irregular) list of lists in Python](http://stackoverflow.com/questions/2158395/flatten-an-irregular-list-of-lists-in-python) – Mohammad Yusuf Feb 01 '17 at 15:55
  • Both of these answers return the list as a list of integers. Although this is a list of numbers...it needs to be returned as a list of individual strings. – K.Jolly Feb 01 '17 at 16:29
  • `map(str, literal_eval('[' + re.sub("['\[\]]","",str(list1)) + ']'))` You can hack like this. – Mohammad Yusuf Feb 01 '17 at 16:31

0 Answers0