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
• 6,110 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 9,660 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 1 day ago in Python by Anjali
+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
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
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
• 9,660 points
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
• 9,660 points

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.