Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

please see my code below,

example_list = [

    ['a','b','c'],

    ['f','g','h'],

    ['i','j','k'],

]

my_string = '''

'''

for s in example_list:

    pass #what will write?

print(my_string)

#ouput should be a 3 line string just like this,

('a','b','c'), 

('f','g','h'), 

('i','j','k');

1 Answer

0 votes
by (36.8k points)

You can try this:

example_list = [

    ['a','b','c'],

    ['f','g','h'],

    ['i','j','k'],

]

my_string = '''

'''

for s in example_list:

  my_string = my_string +  str(tuple(s))  + ',\n'

my_string = my_string.strip(',\n') + ';'

print(my_string)

Output:

('a', 'b', 'c'),

('f', 'g', 'h'),

('i', 'j', 'k');

Do check out Python Data Science Course which helps you understand from scratch. 

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...