Array values in Python

0 votes
In the Code used, I have the values arr1 as 25,26 and arr2 values as A,B and the number of values are always equal in arr1 and arr2

For the following code:

          for i in arr1.split(","):
                print i //prints 25 and 26
 

If i want to map the values of arr1 & arr2, is it not possible to get the values of arr2 in the same loop ?
Nov 28, 2018 in Python by ana1504.k
• 7,430 points
23 views

1 answer to this question.

0 votes
You can use the enumerate function and loop through a list in order to get both its numerical index and its value. The code can be written as :

array1 = arr1.split(',')
array2 = arr2.split(',')
for i,value in enumerate(array1):
   print value, array2[i]
 

This will give the following output:

25 A
26 B
answered Nov 28, 2018 by SDeb
• 12,280 points

Related Questions In Python

0 votes
1 answer

Is it possible to create an array with all values as zero in python?

You can use  np.zeros(4,3) This will create a 4 ...READ MORE

answered May 24 in Python by Anjali
32 views
+4 votes
7 answers
+2 votes
11 answers

How to print array/ list without brackets in python?

name=["a","b","c"] print (', '.join(name)) It will simply take all ...READ MORE

answered Apr 18, 2018 in Python by aayushi
• 750 points
16,358 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 128 views
0 votes
1 answer

Is arr.__len__() the preferred way to get the length of an array in Python?

my_list = [1,2,3,4,5,6,7] len(my_list) # 7 The same works for ...READ MORE

answered Oct 8, 2018 in Python by SDeb
• 12,280 points
44 views
0 votes
1 answer

Python Pandas: selecting element in array column

pa.loc[row] selects the row with label row. pa.loc[row, ...READ MORE

answered May 13 in Python by SDeb
• 12,280 points
26 views