Reputation: 251
Here is the list:
[[('mobile','VB')],[('margin','NN')],[('and','CC')]]
But I want to remove []
from list. Output should be:
[('mobile','VB'),('margin','NN'),('and','CC')]
Upvotes: 0
Views: 53
Reputation: 6288
You can use itertools.chain :
import itertools
def unlist_items(list1):
return list(itertools.chain(*list1))
list1 = [[('mobile','VB')],[('margin','NN')],[('and','CC')] ]
print( unlist_items( list1 ) ) # prints [('mobile', 'VB'), ('margin', 'NN'), ('and', 'CC')]
Upvotes: 0
Reputation: 4255
Using list comprehension
L = [[('mobile','VB')],[('margin','NN')],[('and','CC')]]
R = [ x[0] for x in L ]
Upvotes: 1
Reputation: 302
d={'a':'apple','b':'ball'}
d.keys() # will give you all keys in list
['a','b']
d.values() # will give you values in list
['apple','ball']
d.items() # will give you pair tuple of key and value
[('a','apple'),('b','ball')
print keys,values method one
for x in d.keys():
print x +" => " + d[x]
'
var arr= []; // create an empty array
arr.push({
key: "Name",
value: "value"
});
OR
var array = {};
array ['key1'] = "testing1";
array ['key2'] = "testing2";
array ['key3'] = "testing3";
console.log(array);
or like that
var input = [{key:"key1", value:"value1"},{key:"key2", value:"value2"}];
Upvotes: 0
Reputation: 136
One solution is to iterate over the list and take the first item inside and add it to a new list.
In [1] _list = [[('mobile','VB')],[('margin','NN')],[('and','CC')]]
In [2] cleaned = []
In [3] for item in _list: cleaned.append(item[0])
In [4] print(cleaned)
Out[4] [('mobile', 'VB'), ('margin', 'NN'), ('and', 'CC')]
Upvotes: 0