+ 7

Working with lists

finally i get the right result With my Code. But goes it easier? https://code.sololearn.com/cQsgd9J7zYi0/?ref=app

3rd Jul 2021, 4:19 PM
Angela
Angela - avatar
11 Respuestas
+ 8
https://code.sololearn.com/cth8s2EooHDj/?ref=app
3rd Jul 2021, 5:24 PM
Oma Falk
Oma Falk - avatar
+ 4
You can "zip" the two `list` and extend <lst> by a tuple created from comprehension. lst = [] for ( value, counter ) in zip( times, people ): lst.extend( ( value for x in range( counter ) ) ) print( lst )
3rd Jul 2021, 4:39 PM
Ipang
3rd Jul 2021, 7:09 PM
Tibor Santa
Tibor Santa - avatar
+ 2
A quick C version with output in Python style. https://code.sololearn.com/cqOG5PXAdvnZ/?ref=app
3rd Jul 2021, 8:34 PM
Jan
Jan - avatar
+ 2
Thanks @ all, so many new things for me.
4th Jul 2021, 12:31 PM
Angela
Angela - avatar
+ 2
You can do it using the Lambda and List comprehension: times = [0,1,2] people = [4,8,3] result = [] y = lambda n: [((str(times[n]))*(people[n])) for n in range(3)] # print(y(n)) [[result.append(int(j)) for j in i] for i in y(n)] print(result) #range can be taken as (len(times)) or (len(people))
4th Jul 2021, 2:58 PM
Linpaws J
Linpaws J - avatar
+ 1
Yusra I recommend you to start Python for Beginners course on Sololearn https://www.sololearn.com/Course/Python-for-Beginners/?ref=app
5th Jul 2021, 8:13 AM
blackfish
blackfish - avatar
0
Hii
4th Jul 2021, 3:55 PM
Nikhil Dwivedi
0
Sir I want python code for 7425 ÷550
4th Jul 2021, 4:00 PM
Guna sekaran
Guna sekaran - avatar
0
Pls I'm new and I don't understand any single thing in phython
5th Jul 2021, 12:55 AM
Yusra Ishaq
Yusra Ishaq - avatar
0
Bro I want a help from you can you help me?
5th Jul 2021, 3:03 PM
Anton Jeniff