Reputation: 147
month1=['01','02','03','04','05','06','07','08','09','10','11','12']
month2=['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC']
How to search and match of the given string values from these two string arrays?. For example I want my value of 'APR' to be printed if the given value is '04'?. Currently I am using this method;
for date1, date2 in zip(month1,month2):
if date1=='04':
print(date2)
I am trying to avoid using loop for in this case. Is there any other ways on getting the desired result?. Many thanks.
Upvotes: 0
Views: 42
Reputation: 2243
Get index of "04"
using month1.index('04')
and then use that index to get name of the month.
month2[month1.index("04")]
Upvotes: 1