+ 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')
5 Antworten
+ 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))
+ 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!
+ 2
Abhay, It's working now 😍
Thanks 🥰
+ 1
How about "if i in l":print("i is in list")
+ 1
Abhay, but it will not work if you input "1+b-a"