Membership
Part of the Fundamentals section of Coddy's Python journey — lesson 67 of 77.
You can check whether an element is in the a list or not (in, not in):
2 in [1, 2] # True
3 not in [1, 2] # True
3 in [1, 2] # FalseChallenge
EasyCreate a program that receives two lists and prints a new list of all elements that are in the first list but NOT in the second list.
Cheat sheet
Check if an element is in a list using:
element in list # Returns True if element is in the list
element not in list # Returns True if element is not in the listTry it yourself
# Splits each input string into a list, using commas as separators
lst1 = input().split(",")
lst2 = input().split(",")
# Write your code belowThis lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Logical Operators Part 48Loops
For LoopWhile LoopBreakContinueRecap - FactorialThe Range FunctionNested LoopRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators9Functions
Declare a FunctionArgumentsReturnRecap - Sigma FunctionRecap - Validation FunctionDefault Values12Iterating Over Sequences
Iterating Over ElementsThe Enumerate FunctionIterating Over Strings Part 1Iterating Over Strings Part 2