pythonic way to convert variable to list

前端 未结 8 522
时光说笑
时光说笑 2020-12-24 03:14

I have a function whose input argument can either be an element or a list of elements. If this argument is a single element then I put it in a list so I can iterate over the

8条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-24 03:51

    Your aproach seems right to me.

    It's similar to how you use atom? in Lisp when you iterate over lists and check the current item to see if it is a list or not, because if it is a list you want to process its items, too.

    So, yeah, don't see anything wrong with that.

提交回复
热议问题