0

I have a string input by a user (e.g. "MMXVII"), then I make it an array using list(User_input). Now, I want to check if each character the user has input matches one of the characters in another array containing allowed characters.

So I'd have two lists:

List_Permitted_Characters = ["M", "G", etc . ]
User_input = ["M", "M, "X", "V", "I", "I"]

I need to check if every character in User_input is one of the ones in List_Permitted_Characters

I'm quite new to programming and python, so I'm sorry if this information isn't very helpful.

Barmar
  • 741,623
  • 53
  • 500
  • 612
dhjtricks
  • 37
  • 6
  • Before you choose an approach, think about what you need to do if one or more characters are _not_ on the allowed list. – alexis Sep 30 '17 at 11:03

1 Answers1

3

One way is using sets:

set(User_input).issubset(List_Permitted_Characters)

If this is all you are using List_Permitted_Characters for, you should store is as a set anyway, since the sequential information is irrelevant.

dseuss
  • 971
  • 6
  • 8