Python Introductory Questions

Asked 2 years ago, Updated 2 years ago, 15 views

    for place in val:
        for words in place:
    ```

The overlapping list eg.ist = [Seoul], [Daegu], and [Busan] are extracted and converted into strings like Seoul, Daegu, and Busan. I can't think of how to close the for door above. 
Is there any other way besides that?

python

2022-09-22 10:42

1 Answers

In [1]:ist = ["Seoul"], ["Daegu"], ["Busan"]
In [2]: ', '.join(item for l in ist for item in l)
Out[2]: 'Seoul, Daegu, Busan'

In [3]: import itertools
In [4]: ', '.join(itertools.chain(*ist))
Out[4]: 'Seoul, Daegu, Busan'

I can think of two ways.


2022-09-22 10:42

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.