0

My List is :

 [['kukatpally'], ['gachibowli'], ['Madhapur'], ['Chintal'],........]

I want to show like this

 ['kukatpally', 'gachibowli', 'Madhapur', 'Chintal',....]

so how to delete those '[' and ']' symbols..

Thanks in advance

2
  • then, please accept one that you think the most suitable answer. click on the tick next to the answer. Commented Dec 27, 2013 at 9:01
  • 1
    Please be aware that "those symbols" are not in the list. They just show up when you print a representation of the list. Commented Dec 27, 2013 at 9:09

4 Answers 4

4

Use itertools.chain :

import itertools

l = [['kukatpally', 'somethingelse'], ['gachibowli'], ['Madhapur'], ['Chintal']]

list(itertools.chain(*l))
>> ['kukatpally', 'somethingelse', 'gachibowli', 'Madhapur', 'Chintal']

Or itertools.chain.from_iterable

import itertools

l = [['kukatpally', 'somethingelse'], ['gachibowli'], ['Madhapur'], ['Chintal']]

list(itertools.chain.from_iterable(l))
>> ['kukatpally', 'somethingelse', 'gachibowli', 'Madhapur', 'Chintal']
Sign up to request clarification or add additional context in comments.

Comments

3

Assuming you meant that your sub lists might contain multiple items:

 >>> ls = [['kukatpally'], ['gachibowli'], ['Madhapur'], ['Chintal']]
 >>> new_list = [item for sublist in ls for item in sublist]
 >>> new_list
 ['kukatpally', 'gachibowli', 'Madhapur', 'Chintal']

Comments

1
>>> ls = [['kukatpally'], ['gachibowli'], ['Madhapur'], ['Chintal']]
>>> l = [x[0] for x in ls]
>>> l
['kukatpally', 'gachibowli', 'Madhapur', 'Chintal']
>>> 

Comments

0
new_list = [item[0] for item in old_list]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.