0
import re

input_info_list = [['corre', 'salta', 'dibuja'], ['en el bosque', 'en el patio'], ['2023-02-05 00:00 am', '2022-12-29 12:33 am _--_ 2023-01-25 19:13 pm']]

print(reordered_input_indo_list) # --> output new list

I want to create a list that separates all possible combinations of the elements in the input_info_list list into separate lists inside a new list.

This should be the list you should get:

[[['corre'], ['en el bosque'], ['2023-02-05 00:00 am']]
[['corre'], ['en el patio'], ['2023-02-05 00:00 am']],
[['corre'], ['en el bosque'], ['2022-12-29 12:33 am _--_ 2023-01-25 19:13 pm']],
[['corre'], ['en el patio'], ['2022-12-29 12:33 am _--_ 2023-01-25 19:13 pm']],
[['salta'], ['en el bosque'], ['2023-02-05 00:00 am']],
[['salta'], ['en el patio'], ['2023-02-05 00:00 am']],
[['salta'], ['en el bosque'], ['2022-12-29 12:33 am _--_ 2023-01-25 19:13 pm']],
[['salta'], ['en el patio'], ['2022-12-29 12:33 am _--_ 2023-01-25 19:13 pm']],
[['dibuja'], ['en el bosque'], ['2023-02-05 00:00 am']],
[['dibuja'], ['en el patio'], ['2023-02-05 00:00 am']],
[['dibuja'], ['en el bosque'], ['2022-12-29 12:33 am _--_ 2023-01-25 19:13 pm']],
[['dibuja'], ['en el patio'], ['2022-12-29 12:33 am _--_ 2023-01-25 19:13 pm']]]
Matt095
  • 857
  • 3
  • 9
  • Do you really want all strings in the result to be wrapped in a list that has always just one element? Why not just three strings in one list each time? – trincot Feb 09 '23 at 21:25
  • @trincot Yes, I need all the lists to be grouped in the way indicated by that output, I was trying with various combinations of loops to obtain a final list that looks like the one indicated at the end of the question, although it is quite complicated. – Matt095 Feb 09 '23 at 21:58
  • Please explain how this format is useful? Anyway, the referenced Q&A has the solution for generating the combinations. You can then wrap each element in its own list. – trincot Feb 09 '23 at 21:59
  • @trincot I was researching about data analysis methods through regex-based text tags, then I require text file storage based on this list structure. The list has four sublists [["name of subjects"], ["actions or verbs"], ["places"], ["and times"`]], I remove the name of the subject and leave only the last 3 sublists. So the verb, the place and the time are associated with that person. It is a kind of database inside a string with very low resources. – Matt095 Feb 09 '23 at 22:07
  • I don't see why that has any advantage over `["actions or verbs", "places", "and times"]`? – trincot Feb 09 '23 at 22:09
  • 1
    `[[[val] for val in element] for element in itertools.product(*input_info_list)]` – trincot Feb 09 '23 at 22:10
  • If you translate them, those 3 sublists arranged correctly can form sentences. list[0] + list[1] + list[2] are equal "action place time", "write in computer now". I have a database of lists and I needed a way to read them – Matt095 Feb 09 '23 at 22:11
  • @trincot thanks for the help, I had no idea that this mode of list combinatorics was called cartesian product of a series of lists, although I assume it makes sense because of its similarity to linear algebra matrix products – Matt095 Feb 09 '23 at 22:17

0 Answers0