python - How to split string of multiple lists into individual lists? -


after trying reply below seems lists not string bunch of lists separated "\n" because when try replace quotes triple quotes attributeerror: 'list' object has no attribute 'replace'. change question, how individual lists following apparently not string?

x = [u'tonight'] [u'partly', u'cloudy.', u'clearing', u'this', u'evening.', u'wind',     u'west', u'20', u'km/h', u'gusting', u'to', u'40', u'becoming', u'light',     u'this', u'evening.', u'low', u'9.'] [u'31', u'aug'] [u'increasing', u'cloudiness', u'near', u'noon.', u'wind', u'becoming',     u'southwest', u'30', u'km/h', u'early', u'in', u'the', u'afternoon.',     u'high', u'19.', u'uv', u'index', u'4', u'or', u'moderate.'] [u'night'] [u'clearing', u'in', u'the', u'evening.', u'wind', u'southwest', u'30',     u'km/h', u'becoming', u'light', u'in', u'the', u'evening.', u'low', u'8.'] [u'1', u'sep'] [u'sunny.', u'high', u'22.'] [u'night'] [u'clear.', u'low', u'10.'] [u'2', u'sep'] [u'sunny.', u'high', u'15.'] [u'night'] [u'clear.', u'low', u'plus', u'3.'] [u'3', u'sep'] [u'cloudy', u'with', u'40', u'percent', u'chance', u'of', u'showers.',     u'high', u'12.'] [u'night'] [u'cloudy', u'with', u'30', u'percent', u'chance', u'of', u'showers.',     u'low', u'plus', u'4.'] [u'4', u'sep'] [u'cloudy', u'with', u'30', u'percent', u'chance', u'of', u'showers.',     u'high', u'12.'] [u'night'] [u'cloudy', u'with', u'60', u'percent', u'chance', u'of', u'showers.',     u'low', u'plus', u'4.'] [u'5', u'sep'] [u'cloudy', u'with', u'60', u'percent', u'chance', u'of', u'showers.',     u'high', u'12.'] 

>>> import ast >>> x = """...""" >>> [ast.literal_eval(l) l in x.split('\n')] [[u'tonight'], [u'partly', u'cloudy.', u'clearing', u'this', u'evening.', u'wind', u'west', u'20', u'km/h', u'gusting', u'to', u'40', u'becoming', u'light', u'this', u'evening.', u'low', u'9.'], [u'31', u'aug'], [u'increasing', u'cloudiness', u'near', u'noon.', u'wind', u'becoming', u'southwest', u'30', u'km/h', u'early', u'in', u'the', u'afternoon.', u'high', u'19.', u'uv', u'index', u'4', u'or', u'moderate.'],...] 

make sure surround string in triple quotes.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -