-3

Have a piece of code in python :

print (sorted([(r,len(f)) for r,d,f in os.walk(directory_path)],key=lambda x : x[1],reverse = True))

which gives output like :

[('/etc/ssl/certs', 595), ('/etc/alternatives', 109), ('/etc/', 73), ('/etc/init.d', 52),('/etc/dovecot/conf.d', 27)]

I want something like (without storing it to a variable):

('/etc/ssl/certs', 595)
('/etc/alternatives', 109)
('/etc/', 73)
('/etc/init.d', 52)
('/etc/dovecot/conf.d', 27)]
Ignacio Vergara Kausel
  • 5,521
  • 4
  • 31
  • 41

2 Answers2

1

using pprint

import pprint
pprint.pprint(sorted([(r,len(f)) for r,d,f in os.walk(directory_path)],key=lambda x : x[1],reverse = True))

pprint.pprint([('/etc/ssl/certs', 595), ('/etc/alternatives', 109), ('/etc/', 73), ('/etc/init.d', 52),('/etc/dovecot/conf.d', 27)])
# [('/etc/ssl/certs', 595),
#  ('/etc/alternatives', 109),
#  ('/etc/', 73),
#  ('/etc/init.d', 52),
#  ('/etc/dovecot/conf.d', 27)]
Skycc
  • 3,496
  • 1
  • 12
  • 18
-1

have you ever tried something like that ?

[print(str(x)) for x in sorted([(r,len(f)) for r,d,f in os.walk(directory_path)],key=lambda x : x[1],reverse = True)]
Heros
  • 340
  • 5
  • 15