In: Computer Science
Use python
There is a revenue list, how to covert it from string to int?
Here is the list
['$8,120,000,000', '$8,085,200,000', '$7,703,000,000', '$7,000,000,000', '$5,410,000,000', '$4,212,000,000', '$3,741,400,000', '$3,500,000,000', '$3,000,000,000', '$2,800,000,000', '$2,800,000,000', '$2,529,000,000', '$2,087,600,000', '$2,000,000,000', '$1,900,000,000', '$1,520,000,000', '$1,500,000,000', '$1,500,000,000', '$1,350,000,000', '$1,300,000,000', '$1,400,000,000', '$1,400,000,000', '$1,395,000,000', '$1,200,000,000', '$1,000,000,000', '$1,000,000,000', '$842,000,000', '$887,000,000', '$860,000,000', '$825,000,000', '$799,000,000', '$757,000,000', '$751,000,000', '$701,600,000', '$660,000,000', '$600,000,000', '$577,000,000', '$559,000,000', '$540,000,000', '$532,000,000', '$518,400,000', '$500,000,000', '$500,000,000', '$437,000,000', '$400,000,000', '$350,000,000', '$300,000,000', '$277,000,000'].
Answer:-
Program:-
revenue_list=['$8,120,000,000', '$8,085,200,000',
'$7,703,000,000', '$7,000,000,000', '$5,410,000,000',
'$4,212,000,000', '$3,741,400,000', '$3,500,000,000',
'$3,000,000,000', '$2,800,000,000', '$2,800,000,000',
'$2,529,000,000', '$2,087,600,000', '$2,000,000,000',
'$1,900,000,000', '$1,520,000,000', '$1,500,000,000',
'$1,500,000,000', '$1,350,000,000', '$1,300,000,000',
'$1,400,000,000', '$1,400,000,000', '$1,395,000,000',
'$1,200,000,000', '$1,000,000,000', '$1,000,000,000',
'$842,000,000', '$887,000,000', '$860,000,000', '$825,000,000',
'$799,000,000', '$757,000,000', '$751,000,000', '$701,600,000',
'$660,000,000', '$600,000,000', '$577,000,000', '$559,000,000',
'$540,000,000', '$532,000,000', '$518,400,000', '$500,000,000',
'$500,000,000', '$437,000,000', '$400,000,000', '$350,000,000',
'$300,000,000', '$277,000,000']
print ("Original list is : " + str(revenue_list))
for i in range(0, len(revenue_list)):
value= revenue_list[i].replace(',','')
value=value[1:]
revenue_list[i]=int(value)
print ("Modified list is : " + str(revenue_list))
Output:-
Original list is : ['$8,120,000,000', '$8,085,200,000', '$7,703,000,000', '$7,000,000,000', '$5,410,000,000', '$4,212,000,000', '$3,741,400,000', '$3,500,000,000', '$3,000,000,000', '$2,800,000,000', '$2,800,000,000', '$2,529,000,000', '$2,087,600,000', '$2,000,000,000', '$1,900,000,000', '$1,520,000,000', '$1,500,000,000', '$1,500,000,000', '$1,350,000,000', '$1,300,000,000', '$1,400,000,000', '$1,400,000,000', '$1,395,000,000', '$1,200,000,000', '$1,000,000,000', '$1,000,000,000', '$842,000,000', '$887,000,000', '$860,000,000', '$825,000,000', '$799,000,000', '$757,000,000', '$751,000,000', '$701,600,000', '$660,000,000', '$600,000,000', '$577,000,000', '$559,000,000', '$540,000,000', '$532,000,000', '$518,400,000', '$500,000,000', '$500,000,000', '$437,000,000', '$400,000,000', '$350,000,000', '$300,000,000', '$277,000,000'] Modified list is : [8120000000, 8085200000, 7703000000, 7000000000, 5410000000, 4212000000, 3741400000, 3500000000, 3000000000, 2800000000, 2800000000, 2529000000, 2087600000, 2000000000, 1900000000, 1520000000, 1500000000, 1500000000, 1350000000, 1300000000, 1400000000, 1400000000, 1395000000, 1200000000, 1000000000, 1000000000, 842000000, 887000000, 860000000, 825000000, 799000000, 757000000, 751000000, 701600000, 660000000, 600000000, 577000000, 559000000, 540000000, 532000000, 518400000, 500000000, 500000000, 437000000, 400000000, 350000000, 300000000, 277000000]
If this answer is helpful to you Please Upvote,Thankyou