For a relaxing weekend, do some more questions.
Original title Link: http://www.runoob.com/python/python-exercise-example22.html
title: Two table tennis team to play, each out three people. Team A for A,b,c three, team B for X, Y, z three people. Have drawn lots to determine the contest list. Someone asked the team for a list of matches. A says he does not compare with X, C says he does not compare with x,z, please compile the procedure to find out the list of the three teams.
Analysis: This question can refer to exercise 001, can be converted into a sorting problem.
As long as solving the correspondence between A,b,c and X, Y and Z, the problem can be considered as ABC's order of XYZ. You can use the permutations function.
My Code:
defFun (): forIinchPermutations (['x','y','Z'],3): #枚举出所有xyz的排序if(i[0]!='x' andi[2]!='x' andi[2]!='Z'): #卡xyz顺序的条件Print("a:%s,b:%s,c:%s"% (I[0],i[1],i[2]))
Thinking:
The key is to think of the correspondence in order, so there is a preliminary idea--using loops, and only considering the order of XYZ.
Python3 Exercises 100 Questions--022