How to convert a two nested list of lists into a nested list of tuples in Python?

Ali F

I am trying to convert a two nested list of lists into a nested list of tuples in Python. But I cant get the desired result. The input looks like:

first_list = [['best', 'show', 'ever', '!'],
              ['its', 'a', 'great', 'action','movie']]

second_list = [['O', 'B_A', 'O', 'O'],
               ['O', 'O', 'O', 'B_A','I_A']]

The desired output should look like:

result = [[('best','O'),('show','B_A'),('ever','O'),('!','O')],
          [('its','O'),('a','O'),('great','O'),('action','B_A'),('movie','I_A')]]

Thank you in advance!

Tarik
# zip both lists. You end up with pairs of lists
pl = zip(first_list, second_list)

# zip each pair of list and make list of tuples out of each pair of lists.
[[(e[0], e[1]) for e in zip(l[0], l[1])] for l in pl]

Note: not tested, done on mobile. But you got the idea.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to convert nested list of lists into a list of tuples in python 3.3?

From Dev

Create (nested) List from two Lists in Python

From Dev

how to convert a list of tuples into a lists of part of tuples in python

From Dev

How to round every float in a nested list of tuples

From Dev

Create nested list from two lists

From Dev

Cracking this list of nested lists?

From Dev

How to unpack tuples in nested list?

From Dev

Python convert a list of nested tuples into a dict

From Dev

How to convert a dict of lists to a list of tuples of key and value in python?

From Dev

How to add two nested lists in parallel and append result to a new list in python

From Dev

How to convert a tuple of tuples to a list of lists?

From Dev

Nested List of Lists to Single List of tuples

From Dev

Python Nested tuples to list

From Dev

Create list of tuples with data from nested lists with Linq

From Dev

How do I concatenate two lists inside nested list Python?

From Dev

Filtering nested lists of Tuples in Python

From Dev

Split long list of tuples into nested lists

From Dev

How to remove tuples nested on a list?

From Dev

Python convert a list of lists into a list of tuples

From Dev

How to unpack tuples in nested list?

From Dev

List of tuples from heirarchical nested lists

From Dev

How to add two nested lists in parallel and append result to a new list in python

From Dev

How to flatmap list of lists of lists of tuples in Python?

From Dev

Python convert list of nested tuples to list of tuples

From Dev

How to convert nested list into list containing strings in python?

From Dev

Combine two tuples with a nested list comprehension

From Dev

How to convert a nested list into a dictionary

From Dev

How to makes tuples from a nested list

From Dev

list merging in nested lists

Related Related

  1. 1

    How to convert nested list of lists into a list of tuples in python 3.3?

  2. 2

    Create (nested) List from two Lists in Python

  3. 3

    how to convert a list of tuples into a lists of part of tuples in python

  4. 4

    How to round every float in a nested list of tuples

  5. 5

    Create nested list from two lists

  6. 6

    Cracking this list of nested lists?

  7. 7

    How to unpack tuples in nested list?

  8. 8

    Python convert a list of nested tuples into a dict

  9. 9

    How to convert a dict of lists to a list of tuples of key and value in python?

  10. 10

    How to add two nested lists in parallel and append result to a new list in python

  11. 11

    How to convert a tuple of tuples to a list of lists?

  12. 12

    Nested List of Lists to Single List of tuples

  13. 13

    Python Nested tuples to list

  14. 14

    Create list of tuples with data from nested lists with Linq

  15. 15

    How do I concatenate two lists inside nested list Python?

  16. 16

    Filtering nested lists of Tuples in Python

  17. 17

    Split long list of tuples into nested lists

  18. 18

    How to remove tuples nested on a list?

  19. 19

    Python convert a list of lists into a list of tuples

  20. 20

    How to unpack tuples in nested list?

  21. 21

    List of tuples from heirarchical nested lists

  22. 22

    How to add two nested lists in parallel and append result to a new list in python

  23. 23

    How to flatmap list of lists of lists of tuples in Python?

  24. 24

    Python convert list of nested tuples to list of tuples

  25. 25

    How to convert nested list into list containing strings in python?

  26. 26

    Combine two tuples with a nested list comprehension

  27. 27

    How to convert a nested list into a dictionary

  28. 28

    How to makes tuples from a nested list

  29. 29

    list merging in nested lists

HotTag

Archive