1 #!/usr/bin/env python3.52 #Coding:utf-83 #Suppose you have a list that writes a function that takes a list value as an argument and returns a string4 #The string contains all the table entries, separated by commas and spaces, and inserted before the last value and5 #requires the function to handle any list passed to it6 7 #spam = input (' Please input a list: ')8 #i just started to pass the list from user input, but it didn't work.9 Ten #4.10.1 one Print("4.10.1 answer:") a defchlist_str (spam): -spam[-1] =' and'+ spam[-1] -Str_list =', '. Join (spam) the returnstr_list -New_str = Chlist_str (['Apple','Banana','Tofu','Cats']) - Print("Convert str is:") - Print(new_str) + - #4.10.2 + #the goal of this problem is to make a list of nested lists to be Converted. a Print("4.10.2 answer:") atGrid = [['.','.','.','.','.','.'], -['.','o','o','.','.','.'], -['o','o','o','o','.','.'], -['o','o','o','o','o','.'], -['.','o','o','o','o','o'], -['o','o','o','o','o','.'], in['o','o','o','o','.','.'], -['.','o','o','.','.','.'], to['.','.','.','.','.','.']] + - #the first implementation method, because the column length of the list is not equal, the outer loop of the number of newline should be the length of the child List. the forRowinchRange (0,len (grid[0)): * forColinchRange (0,len (grid)): $ #print (". join (grid[col][row]), End=")Panax Notoginseng Print(grid[col][row],end="') - Print() the + #the second method of implementation, a forRowinchZip (*grid): the forColinchRow: + #print (". join (col), End=") - Print(col,end="') $ Print()
Python Programming Quick Start 4th Chapter Practical Project Reference Answer