Are there dictionary comprehensions in Python? (Problem with function returning dict) -


I know about the understanding of the list, which is about understanding the word?

Expected Output: <> & gt; & Gt; & Gt; Count Kraahar ('google') {'E': 1, 'G': 2, 'L': 1, 'O': 2}> gt; & Gt; & Gt; Counter Letters ('apple') {'A': 1, 'E': 1, 'L': 1, 'P': 2} & gt; & Gt; & Gt; Code (I'm starting one):

  def countChar (word): l = [] #get In word A for C: l.append (c) sortedList = sorted ( L) uniqueSet = set (sortedList) returns {item: word.count in item} uniqueSet}   

What's the problem with this code? Why do I get this SyntaxError ? Return {item: word.count} ^ Syntax Error in UniqueSet in Item: Invalid Sentence

edit : As FF noted in comments and other answers, there is an understanding of a dictionary for Python 2.7 or newer.

  def countChar (word): return word (item, word quote (item)) for item in set (word) & gt; & Gt; & Gt; Count Kraahar ('google') {'E': 1, 'G': 2, 'O': 2, 'L': 1}> gt; & Gt; & Gt; No need to convert  (code 'A': 1, 'P': 2, 'E': 1, 'L': 1}   

/ Code> Sorts it after sorting it in a list or changing it to a set:

  & gt; & gt; & gt; set ('Google') set ( ['E', 'O', 'G', 'L'])   

There is no understanding of the dictionary for Python 2.6 and below, which may cause you to syntax error Why are you looking at the options or creating a list of Key-Value Tulips by using the generator? It is built.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -