1, first a group of friends to ask such questions
This error is obvious, the object of type int is not supported by iteration, this is obvious. The solution given is also very simple, just to change the int type number to the STR type.
2, the group friend said that his tuple may have any type of data, the above method may not apply, and then he gave an example, said the data is this
Again int type cannot iterate error, is the parameter passed in is not c[0]? But what?
3, it appears in the above map (List,c[0]) passed in the list of parameters is really not c[0], we need to learn what the map what the hell? Let's take a look at the map's help document
Let's just look at the first sentence, it is the parameter list of the various items using function functions, and finally output a list of results. Give a simple example to explain this sentence,
First, an add function is defined, and the argument list is [2,3,4], so the actual value of each incoming add () function is a value in the argument list, not the parameter list itself, and is run iteratively.
So map (List,c[0]), the actual incoming list is the number 1 in c[0], and list (1) is wrong.
In fact the group of friends wanted the result is [[1, ' Zhang '],[2, ' san '], so the correct wording is map (list,c)
My Love Python group Friends questions and answers