List-derived
Example one: Any number within 30 that can be divisible by 3
List derivation 1
for inch if is 0] Print (multiples) # Output: [0, 3, 6, 9, (+), (+) ,-
Example two: The square of all numbers within 30 that can be divisible by 3
List Derivation 2
Example three: Find all names in a nested list with two ' E ' names
Nested list Expressions
names = [['Tom','Billy','Jefferson','Andrew','Wesley','Steven','Joe'], ['Alice','Jill','Ana','Wendy','Jennifer','Sherry','Eva']]Print([Name forLstinchNames forNameinchLstifName.count ('e') >= 2])#Note the traversal order, which is the key to the implementation
Dictionary derivation type
Example one: Swap the key and value of a dictionary
dictionary derivation type one
Mcase = {'a'b': in Mcase}print(mcase_frequency)
Example two: Merge the value values of the case, unify the K into lowercase
Dictionary derivation Formula Two
Mcase = {'a' b'a' Z ': 3 for in Mcase.keys ()}print(mcase_frequency)
Set Deduction formula
Example: Calculating the square of each value in a list, with self-weight function
Set Deduction Formula One
Exercises:
Example 1: Filter out a list of strings that are less than 3 long and convert the rest to uppercase
Example 2: (x, y) where x is an even number between 0-5 and Y is an odd-numbered list of Ganso between 0-5
Example 3: A list of 3,6,9 in M = [[1,2,3],[4,5,6],[7,8,9]]
Answer
for inch if len (name) >3forif in if y%2==1 for in
python-Generator-Advanced ~ various derivation