0

I want to rename a list of files without using a for loop.

It is possible by using the map function like this:

import os

list( map( (lambda x: os.rename(x, x + "foo")), filelist ) )

...but it's not convenient: the returned map object needs to be "activated" by the list function.

So I'm looking for a kind of map procedure that would do the same, without shenanigans.

martineau
  • 119,623
  • 25
  • 170
  • 301
  • use a list comprehension instead.. wait...do a loop – Jean-François Fabre Dec 06 '20 at 20:30
  • 1
    It's generally considered a bad practice to use `map` or list comprehensions just for side effects - see for instance this question and its various answers: https://stackoverflow.com/questions/5753597/is-it-pythonic-to-use-list-comprehensions-for-just-side-effects - you don't say _why_ you want to avoid a for loop, which would be the usual idiom. – Peter DeGlopper Dec 06 '20 at 20:32

0 Answers0