0

Given a matrix with string and empty cells inside (name) print(name)

[]
['Puchkin A.']
[]
['Kudryashova V.']
[]

How to convert this matrix into a list, approximately:

[[], ['Puchkin A.'], [], ['Kudryashova V.'], []]

12
  • Your input does not look like valid. Please double check. Is something like this: `inputs = "[] ['Puchkin A.'] ['Kudryashova V.'], [] " Or ? Commented Aug 6, 2021 at 10:56
  • So you dont want the middle list from the string? E.g. [[], ['Puchkin A.'], [], ['Kudryashova V.'], []] Commented Aug 6, 2021 at 10:57
  • @user56700 Oh, I'm sorry. I missed it Commented Aug 6, 2021 at 11:00
  • @DanielHao Sorry. I missed [] Commented Aug 6, 2021 at 11:01
  • @Mr.Dandomi Please add the exact input you have so we can give you a correct answer, if it's not a string, then what is it? Please provide an example. Commented Aug 6, 2021 at 11:15

1 Answer 1

1

You could use numpy's built in function matrix() and then use tolist()

Here's an example:

import numpy as np
matrix = [[],
['Puchkin A.'],
[],
['Kudryashova V.'],
[]]
print((np.matrix(matrix)).tolist())
Sign up to request clarification or add additional context in comments.

2 Comments

pastebin.com/dZyhLm7Y Look at the 68th line A regular expression creates a matrix with string inside
raise ValueError("matrix must be 2-dimensional") ValueError: matrix must be 2-dimensional pastebin.com/iWp6MGQX

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.