kcl-lang / kcl-lang.io

KCL Website and Documentation Repo: https://kcl-lang.io
https://kcl-lang.github.io
Apache License 2.0
13 stars 35 forks source link

[FAQ] convert a list of lists to a single list #310

Closed wilsonwang371 closed 5 months ago

wilsonwang371 commented 5 months ago

General Question

How do I convert [[1, 2], [3, 4]] to [1, 2, 3,4] in kcl?

wilsonwang371 commented 5 months ago

an ugly solution would be:

_listOfLists = [genList(i) for i in inputList]
_listOfLists = [i for sub in _listOfLists for i in sub]
Peefy commented 5 months ago

The code is

data = sum([[1, 2], [3, 4]], [])
wilsonwang371 commented 5 months ago

Can we provide some function like flatten in the future?

Peefy commented 5 months ago

Yes, we do.

d4v1d03 commented 5 months ago

Hey @Peefy ,added the PR #325

Peefy commented 5 months ago

Closed by #325