Advertisement
Guest User

lesson3.py

a guest
Mar 30th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. from typing import List
  2.  
  3.  
  4. # Zadanie 3 - po bólach
  5. def flat_list(list_in: List):
  6.     list_out = []
  7.     for lists in list_in:
  8.         if type(lists) is list:
  9.             for number in lists:
  10.                 list_out.append(number)
  11.         else:
  12.             list_out.append(lists)
  13.  
  14.     return list_out
  15.  
  16.  
  17. def explode_list(li_in: List):
  18.     for element in li_in:
  19.         if type(element) is list:
  20.             explode_list(li_in=element)
  21.         else:
  22.             print(element, end=' ')
  23.  
  24. # def recursion_infinite():
  25. #     recursion_infinite()
  26. #
  27. # recursion_infinite()
  28.  
  29.  
  30. test_list_1 = [1, 2, [2, 3, 2], [11, 10]]
  31. test_list_2 = [1, 2, [2, 3, 2], [[1, 2], [2, 4, 5]]]
  32.  
  33. print(flat_list(test_list_1))
  34. explode_list(test_list_1)
  35.  
  36. print(flat_list(test_list_2))
  37. explode_list(test_list_2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement