+ 2

[SOLVED] How can I simplify this code?

i = input() l = ['+','-','×','÷'] print('list = '+str(l)) print('input: '+i) if l[0] in i: b = i.find(l[0]) print(l[0]+' is in list') if l[1] in i: b = i.find(l[1]) print(l[1]+' is in list') if l[2] in i: b = i.find(l[2]) print(l[2]+' is in list') if l[3] in i: b = l.find(l[3]) print(l[3]+' is in list')

13th Sep 2021, 9:53 AM
Fꫀⲅძ᥆͟ᥙ᥉᯽
Fꫀⲅძ᥆͟ᥙ᥉᯽ - avatar
5 ответов
+ 6
MD. Ferdous Ibne Abu Bakar does the following code helps ? a="1+b-a" li=["+","-","×","÷"] c=list(filter(lambda x:x in a,li)) print("\n".join(f"{x} in a" for x in c))
13th Sep 2021, 10:19 AM
Abhay
Abhay - avatar
+ 7
MD. Ferdous Ibne Abu Bakar , i think you need to give us more information, otherwise we have to guess what your purpose is. do you want to parse the input for mathematical operators? are you going to do something like a equation solver? so you can see that it is always better to give a complete and clear task description, samples of input and output,... happy coding and good success!
13th Sep 2021, 10:10 AM
Lothar
Lothar - avatar
+ 2
Abhay, It's working now 😍 Thanks 🥰
13th Sep 2021, 10:23 AM
Fꫀⲅძ᥆͟ᥙ᥉᯽
Fꫀⲅძ᥆͟ᥙ᥉᯽ - avatar
+ 1
How about "if i in l":print("i is in list")
13th Sep 2021, 9:58 AM
Abhay
Abhay - avatar
+ 1
Abhay, but it will not work if you input "1+b-a"
13th Sep 2021, 10:05 AM
Fꫀⲅძ᥆͟ᥙ᥉᯽
Fꫀⲅძ᥆͟ᥙ᥉᯽ - avatar