Home > other > Small white inquired, in front of the traverse if statements, there are different types of len deter
Small white inquired, in front of the traverse if statements, there are different types of len deter
Time:10-08
6.4.2 python from entry to practice the sixth chapter, there is a development, I really don't understand here!
# multiple keys stored list values, Favorite_languages={ 'jen: [' python', 'ruby'], 'Sarah: [' c'], 'Edward: [' ruby,' go '], 'phil: [' python', 'haskell'], } For the name, the languages in favorite_languages. The items () : Print (" \ n "+ name. Title () +" 's favorite languages are: ") For language in languages: Print (" \ t "+ language. The title ())
Development: in order to further improve the program, but for loop of the traverse the dictionary first add an if statement, by looking at the len (languages) value to determine the current respondents like whether there is a variety of language, if he likes to many languages, like previous display output; If there is only one, the wording of the corresponding modified output, such as display Sarah 's favorite language is C,
Here the expansion of what to do?
Happy New Year!!!!!
CodePudding user response:
For the name, the languages in favorite_languages. The items () : Print (" \ n "+ name. Title () +" 's favorite languages are: ") If len (languages)!=1: For language in languages: Print (" \ t "+ language. The title ()) The else: Print (I don't know how to write)
CodePudding user response:
For the name, the languages in favorite_languages. The items () : If len (languages)==1: Print (name. Title () + "' s favorite laguages is:") The else: Print (" \ n "+ name. Title () +" 's favorite languages are: ") For language in languages: Print (" \ t "+ language. The title ()) Reference code out of the 1/f, as a result, I wrote before is STR (len