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,910 points
795 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
• 13,300 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, 2019 in Python by Anjali
1,111 views
+4 votes
7 answers
+1 vote
12 answers
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,402 views
0 votes
1 answer
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
• 13,300 points
932 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, 2019 in Python by SDeb
• 13,300 points
13,316 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP