+ 1

What can you use lists for in Python?

Say, if you are creating a small game or a useful bit of code. I haven't seen any real uses for them yet, just little things where a name is printed out letter by letter.

15th Nov 2018, 1:16 PM
Daniel Sheldon
Daniel Sheldon - avatar
2 ответов
+ 2
List or tuple or set are all ITERABLE containers kind of object in Python [Everything in Python is object], which are basically used to store countably finite number of elements. Think of it like a basket containing fruits where basket represents the iterable and fruits as its element. A simple use case: Suppose you want to perform binarization (image processing operation) in every images available in a folder. Then you can store the image file names in a list and access each image file by it's name and perform binarization.
16th Nov 2018, 3:06 AM
Tamoghna Saha
+ 10
Well lists are used when you want to store data or characteristics of something in "The same place". For example let's say you have a function called prime() that says if a number is prime or not and you want to check and print the prime numbers from a to b in a "nice way": instead of: for i in range(a,b+1): if prime(i): print(i) You can say: l=[] for i in range(a,b+1): if prime(i): l.append(i) print(f"The prime numbers from {a} to {b} are: {l if l else 'none'} .") Of course there are others examples but this one was the first that came to my mind.
15th Nov 2018, 5:53 PM
Uni
Uni - avatar