Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need assistance on correctly running this python code python code #!/usr/bin/python import sys for line in sys.stdin: line = line.strip() val = line.split(|) lo_quantity =

Need assistance on correctly running this python code

python code

#!/usr/bin/python

import sys

for line in sys.stdin:

line = line.strip()

val = line.split("|")

lo_quantity = val[8]

lo_revenue = val[12]

lo_discount = val[11]

print '%s\t%s\t%s' % (lo_quantity, lo_revenue,

cat lineorder.tbl | tr '|' '\t' | python myMapper.py

Error message

File "myMapper.py", line 7, in

lo_quantity = val[8]

IndexError: list index out of range

DATA

1|1|7381|155190|828|19960102|5-LOW|0|17|2116823|17366547|4|2032150|74711|2|19960212|TRUCK| 1|2|7381|67310|163|19960102|5-LOW|0|36|4598316|17366547|9|4184467|76638|6|19960228|MAIL| 1|3|7381|63700|71|19960102|5-LOW|0|8|1330960|17366547|10|1197864|99822|2|19960305|REG AIR| 1|4|7381|2132|943|19960102|5-LOW|0|28|2895564|17366547|9|2634963|62047|6|19960330|AIR| 1|5|7381|24027|1625|19960102|5-LOW|0|24|2282448|17366547|10|2054203|57061|4|19960314|FOB| 1|6|7381|15635|1368|19960102|5-LOW|0|32|4962016|17366547|7|4614674|93037|2|19960207|MAIL| 2|1|15601|106170|1066|19961201|1-URGENT|0|38|4469446|4692918|0|4469446|70570|5|19970114|RAIL| 

Data Table

reate table lineorder ( lo_orderkey int, lo_linenumber int, lo_custkey int, lo_partkey int, lo_suppkey int, lo_orderdate int, lo_orderpriority varchar(15), lo_shippriority varchar(1), lo_quantity int, lo_extendedprice int, lo_ordertotalprice int, lo_discount int, lo_revenue int, lo_supplycost int, lo_tax int, lo_commitdate int, lo_shipmode varchar(10) ) 

Do not understand why I constantly get an error message

try to successfully run this python code also

#!/usr/bin/python

import sys

lo_dic = {}

lo_list = []

sum_rev = 0;

for line in sys.stdin:

line = line.strip()

lo_quantity, lo_revenue, lo_discount = line.split("\t")

if int(lo_discount) < 3:

if lo_quantity in lo_list:

lo_dic[lo_quantity].append(int(lo_revenue))

else:

lo_list.append(lo_quantity)

lo_dic[lo_quantity] = []

lo_dic[lo_quantity].append(int(lo_revenue))

for keys, values in lo_dic.iteritems():

if keys in lo_list:

sum_rev = sum_rev + sum(values)

print '%s' % (sum_rev)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions