Home > Net >  Substitute for vector<vector<int>> in python
Substitute for vector<vector<int>> in python

Time:02-16

What is the substitute of vector<vector>a in python?

Will this work?

a=[[]]

CodePudding user response:

You can specify it as a list of list of int by:

from typing import List

a = [[]]  # type: List[List[int]]

Python itself will not complain if you try to append a string:

a[0].append('hello')

but running mypy over it will complain:

c:\tmp> mypy vecint.py
vecint.py:6: error: Argument 1 to "append" of "list" has incompatible type "str"; expected "int"
Found 1 error in 1 file (checked 1 source file)

CodePudding user response:

This isn't equal, because len(a) = 1. In C , an empty vector has size 0.

There's no simple solution, because in Python an empty list is not a list of lists. It's just a plain list.

  • Related