9 odpowiedzi
+ 2
That was an example how to create a list of numbers using input by space. Map is function that gives you instructions applying some function to each item. So map receives two parameters: some function and list of items. In that example input().split() gives you a list of elements separated by space. But those elements aren't numbers. And "int" in map converts all that elements to integers. Finally you have a list of numbers.
+ 11
# That what you mean?
l = list()
for i in range(10):
l.append(i/2)
print(l)
# or this:
l = [i/2 for i in range(10)]
print(l)
+ 9
l = [input("Gimme " + str(i) + ": ") for i in range(10)]
+ 4
For example: list l of numbers from 0 to determined n:
n=int(input())
l=[i for i in range(n+1)]
Other way:
for i in range(n+1):
l.append(i)
You can use other methods to modify your list as you want.
+ 4
In this case you can use map with list comprehension.
l=list(map(int, input().split()))
print(l)
+ 1
In this case you can use map with list comprehension.
l=list(map(int, input().split()))
print(l)
Sir can you explain it more clearly .
+ 1
Sir thanka a lot ☺. Now I got it. Time to play with it...
0
Thank you frnds but this loops assigns index values to list l, but I need to get input in runtime. So can u help me with it's solution. ☺
0
Frnds i have found solution in another logic :
N = int(input("Enter Size of Array:"))
l = list()
print("Enter The Elements:")
for i in range(N):
ip = int(input())
l.append(ip)
print("Elements in list:",l)
sum_number = 0
for i in range(N):
sum_number = int( l[i] ) +sum_number
print("Sum of Array",sum_number)
This program gets input from user and then sums all elements in the list .
Thank you guys :)