<reponame>Virksaabnavjot/MapperReducer<filename>train/Mapper.py
#!/usr/bin/env python
import sys

# Mapper to return  10 passengers by age groups
# Data source: https://www.kaggle.com/c/titanic/data
# Data header: "PassengerId" "Survived"	"Pclass" "Name"	"Sex" "Age" "SibSp" "Parch" "Ticket" "Fare" "Cabin" "Embarked"

myList = []
n = 10	# Number of top N records

for line in sys.stdin:
	# remove leading and trailing whitespace
	line = line.strip()
	# split data values into list
	data = line.split(",")

	# convert age (currently a string) to int
	try:
		age = int(data[6])
	except ValueError:
		# ignore/discard this line
		continue

	# add (age, record) touple to list
	myList.append( (age, line) )
	# sort list in reverse order
	myList.sort(reverse=True)
	
	# keep only first N records
	if len(myList) > n:
		myList = myList[:n]
		
# Print top N records
for (k,v) in myList:
	print(v)
#!/usr/bin/env python
import sys

# Mapper to return  10 passengers by age groups
# Data source: https://www.kaggle.com/c/titanic/data
# Data header: "PassengerId" "Survived"	"Pclass" "Name"	"Sex" "Age" "SibSp" "Parch" "Ticket" "Fare" "Cabin" "Embarked"

myList = []
n = 10	# Number of top N records

for line in sys.stdin:
	# remove leading and trailing whitespace
	line = line.strip()
	# split data values into list
	data = line.split(",")

	# convert age (currently a string) to int
	try:
		age = int(data[6])
	except ValueError:
		# ignore/discard this line
		continue

	# add (age, record) touple to list
	myList.append( (age, line) )
	# sort list in reverse order
	myList.sort(reverse=True)
	
	# keep only first N records
	if len(myList) > n:
		myList = myList[:n]
		
# Print top N records
for (k,v) in myList:
	print(v)
#!/usr/bin/env python # Mapper to return  10 passengers by age groups # Data source: https://www.kaggle.com/c/titanic/data # Data header: "PassengerId" "Survived"	"Pclass" "Name"	"Sex" "Age" "SibSp" "Parch" "Ticket" "Fare" "Cabin" "Embarked" # Number of top N records # remove leading and trailing whitespace # split data values into list # convert age (currently a string) to int # ignore/discard this line # add (age, record) touple to list # sort list in reverse order # keep only first N records # Print top N records