I'd like to pick out a list that has a specific element that I want from the list

Asked 2 years ago, Updated 2 years ago, 20 views

 a_list = ["Black Bean Noodles" and "Spicy Seafood Noodles"]
b_list = ["Fried rice", "Mapa Tofu"]
c_list = ["Sushi", "Fried food"]
...
z_list = ["Some", "Element"]

def example():
    ~~~

When there are several lists like above,

example('jjamppong')
["Black Bean Noodles" and "Spicy Seafood Noodles"] Output
example ('Mapa Tofu')
["Fried rice", "Mapa Tofu"] Output
example ('Fried')
["Sushi", "Fried food"] Output

I want to write a code that works like this.

python

2022-09-21 11:51

2 Answers

all_list = [['a', 'b', 'c'], ['a', 'd', 'e'], ['b','g','e']]

def example(word):
    l = []
    for lst in all_list:
        if word in lst:
            l.append(lst)
    return l
print(example('a'))  # [['a', 'b', 'c'], ['a', 'd', 'e']]
print(example('e'))  # [['a', 'd', 'e'], ['b', 'g', 'e']]


2022-09-21 11:51

 a_list = ["Black Bean Noodles" and "Spicy Seafood Noodles"]
b_list = ["Fried rice", "Mapa Tofu"]
all_list = []
all_list.append(a_list)
all_list.append(b_list)

def example(_txt):
    for i in range(0,len(all_list)):
        for j in range(0, len(all_list[i])):
            if _txt == all_list[i][j]:
                return all_list[i][j]

print(example('jjamppong'))
'''
===============
Jjambbong
'''

I tried it on the level that doesn't hurt the original code I don't know anything about nose.


2022-09-21 11:51

If you have any answers or tips


© 2025 OneMinuteCode. All rights reserved.