0

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')]
1
  • Why did you create it that way in the first place? Commented Sep 8, 2016 at 6:53

4 Answers 4

1

Using list comprehension

L = [[('mobile','VB')],[('margin','NN')],[('and','CC')]]
R = [ x[0] for x in L ]
Sign up to request clarification or add additional context in comments.

Comments

0

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')]

Comments

0
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"}];

Comments

0

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')]

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.