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: <> What's the problem with this code? Why do I get this edit : As FF noted in comments and other answers, there is an understanding of a dictionary for Python 2.7 or newer. / Code> Sorts it after sorting it in a list or changing it to a set: 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. & 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}
SyntaxError ?
Return {item: word.count} ^ Syntax Error in UniqueSet in Item: Invalid Sentence
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}
& gt; & gt; & gt; set ('Google') set ( ['E', 'O', 'G', 'L'])
Comments
Post a Comment