(no title)
cyclotron3k | 1 year ago
Pathname.glob('*').filter { |f| f.file? }.each_with_object({}) { |f, h| h[f.size] = f }
Whereas the equivalent Python would be: result = {}
for file_path in glob.glob('*'):
if os.path.isfile(file_path):
result[os.path.getsize(file_path)] = file_path
Or capitalizing a string in Ruby: string.split(' ').map(&:capitalize).join(' ')
And in Python: words = string.split(' ')
capitalized_words = [word.capitalize() for word in words]
result = ' '.join(capitalized_words)
Python seems to be more convoluted and verbose to me, and requires more explicit variable declarations too. With the Ruby you can literally read left to right and know what it does, but with the Python, I find I have to jump about a bit to grok what's going on. But maybe that's just my lack of Python experience showing.
pseudalopex|1 year ago
ndand|1 year ago
sgarland|1 year ago
The file example you gave could also be turned into a dict comprehension if desired. Iām on mobile, but I think this would work.