0

How can I fill list with "for" loop in python?

Like in c++ for(int i=0;i<=10;i++){ cin>>a[i];}

16th Dec 2019, 7:20 AM
Almas The best
Almas The best - avatar
7 Respuestas
+ 4
Almas The best Lists don't have predefined sizes, the size will change like it will get items.
16th Dec 2019, 8:14 AM
Seb TheS
Seb TheS - avatar
+ 3
Are you talking about list comprehensions? List comprehension examples: [i for i in range(5)] #[0, 1, 2, 3, 4] [i * i for i in range(5)] #[0, 1, 4, 9, 16] [i for i in range(10) if i % 2 != 0] #[1, 3, 5, 7, 9] The for loop of C++ doesn't seem to have anything related to list "filling". The list comprehensions do not correspond the C++ sample.
16th Dec 2019, 7:50 AM
Seb TheS
Seb TheS - avatar
+ 2
Oops, I understood as cout, sorry.
16th Dec 2019, 7:53 AM
Seb TheS
Seb TheS - avatar
+ 2
Here's the correspondings (The list a must have atleast 10 items): for i in range(10): a[i] = input() i = 0 while i < 10: a[i] = input() i += 1
16th Dec 2019, 8:00 AM
Seb TheS
Seb TheS - avatar
0
No I mean that i should input elements in loop
16th Dec 2019, 7:53 AM
Almas The best
Almas The best - avatar
0
Thx
16th Dec 2019, 8:12 AM
Almas The best
Almas The best - avatar