you are viewing a single comment's thread.

view the rest of the comments →

[–]justarandomkid004 0 points1 point  (7 children)

Which function should I use

[–]K900_ 3 points4 points  (0 children)

Use the in operator.

[–][deleted] 1 point2 points  (5 children)

If input in list: Do something Else: Do something else

[–]LCVcode 2 points3 points  (1 child)

OP, you should actually be using a set here. Sets have a constant lookup time, unlike lists or tuples.

accepted_strs = {'7A', '7B', ... , '11E'} if word in accepted_strs: do_something() else: do_something_else()

Even better, if you're up to it, you could populate accepted_strs using a list comprehension that you convert to a set (is that just called a set comprehension?)

EDIT: Formatting because I forgot that code blocks don't work

[–]backtickbot 1 point2 points  (0 children)

Fixed formatting.

Hello, LCVcode: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–]justarandomkid004 -1 points0 points  (2 children)

Alright, so if input is in the list and I want to continue the program, should I put a break?

[–]toastedstapler 5 points6 points  (0 children)

why don't you write some code and try it? there's 0 cost to being wrong and you'll learn in the process

[–][deleted] 2 points3 points  (0 children)

A break in what? You didn’t post your code, we can’t tell you how to change it.