Home > Software engineering >  How to I create list comprehension
How to I create list comprehension

Time:04-01

Hello I'm new to python and want to make a the for loop more concise using the list comprehension method these are the below. What is a way that I can do that?

if isinstance(value, list):
    new_value_list = []
    for item in value:
        replaced_text = substitute_jirae_text(item)
        new_value_list.append(replaced_text)
     section_dict[key] = new_value_list
else: 

CodePudding user response:

Something like this

if isinstance(value, list):
     section_dict[key] = [substitute_jirae_text(item) for item in value]
else: 

CodePudding user response:

what about this?

new_value_list = [substitute_jirae_text(item) for item in value)]
  • Related