python学习笔记(二):递归函数

如何利用python编程列举出多层列表中所有的数据?这里给出递归的方法来完成编程。

def print_lol(the_list):
	for each_item in the_list:
		if (isinstance(each_item,list)):
			print_lol(each_item)
		else:
			print(each_item)
测试例子:
>>> array=[1,['a','b','c',['=','-','+']],'#']
>>> print_lol(array)


 

你可能感兴趣的:(python学习笔记(二):递归函数)