https://kotlinlang.org logo
#getting-started
Title
# getting-started
a

Ahmed

12/01/2021, 3:18 PM
hey guys, what is the equavilant of this python code
Copy code
s = "string"
list = [s * 10]
basically, I just want to create a list of objects each of them is the same string actually
j

Joffrey

12/01/2021, 3:19 PM
Probably:
Copy code
val list = List(10) { "string" }
This
List
factory function takes a desired size and a lambda. The lambda is called
size
times with an element index as argument (ignored here), and it should return the desired value for the element at that index
👌 2
a

Ahmed

12/01/2021, 3:22 PM
Perfect! thanks a lot
k

Klitos Kyriacou

12/01/2021, 4:16 PM
By the way, you probably meant
[s]*10