Jul-21-2020, 04:49 AM
list.append(item) does not return a list. The reason for this is append modifies the list instead of creating a new list.
Your function should return a list but it doesn't. You throw the list away as soon as the function exits. You try to get the list by using a variable that has the same name (seznam) as a local variable in the function, but will not work. This doesn't matter much because you never call your triangle function anyway.
You are writing this program in Python, so use Python loops, not C loops.
Your function should return a list but it doesn't. You throw the list away as soon as the function exits. You try to get the list by using a variable that has the same name (seznam) as a local variable in the function, but will not work. This doesn't matter much because you never call your triangle function anyway.
You are writing this program in Python, so use Python loops, not C loops.
five_a = [] for a in 'aaaaa': five_a .append(a) # or for _ in range(5): five_a .append('a')There are shorter ways than using a loop to initialize a list. You can use a list comprehension:
five_a = ['a' for _ in range(5)])Or you can use an initializer.
five_a = (['a']*(5))To get a list of lists you could have a loop inside of a loop, or you could put an list comprehension or an initialize inside a loop. You could also use a list comprehension that uses a generator to make the inner and outer lists. Or you could use a generator generator inside of a generator. Your triangle generator program can be written in a single line of Python code.