does anyone know what this does, ... freq = {} for x in sequence: freq[x] = freq.get(x,0) + 1 return freq Thanks.
In what language? What is sequence? Is it a standard thing in that language?
Because you set freq to some sort of empty set or mapping, then go to for x in sequence... well, I don't see sequence defined....
freq = {} # initiates a dictionary for x in sequence: # will iterate all elements of sequence, no matter the type freq[x] = freq.get(x,0) + 1 # will associate key x of dictionary freq to the value of get(x,0)+1: #+if key x is found in freq, its value is returned, if not - 0 is returned return freq # returns the entire dictionary freq
And what does it do if sequence is undefined?
well, probably shell throws out an error like: 'sequence undefined' :)
But here the sequence type is not so relevant as Python can iterate any iterable element.
Thanks!
Join our real-time social learning platform and learn together with your friends!