+ 2

[Solved] Where is the difference?

Sorry, if this is a newbie question but why does this code work: import string astring=str(input()) for i in astring: if i not in string.ascii_letters and i not in string.digits and i != " ": #Do something .. and this code not: import string astring=str(input()) for i in astring: if i not in [string.ascii_letters, string.digits, " "]: #Do something Any suggestions how to shorten the task more?

7th Jul 2020, 1:26 PM
Zaaak
Zaaak - avatar
2 Antworten
+ 9
You need to concatenate the lists. For example, list1 + list2 + list3
7th Jul 2020, 1:31 PM
Gordon
Gordon - avatar
+ 4
so easy, thank you .. it is really an easy way: for i in astring: if i not in (string.ascii_letters + string.digits + " "):
7th Jul 2020, 1:35 PM
Zaaak
Zaaak - avatar