i have this list:
[\'Boston Americans\', \'New York Giants\', \'Chicago White Sox\', \'Chicago Cubs\', \'Chicago Cubs\', \'Pittsburgh Pirates\', \'Philadelph
players = ['Boston Americans', 'New York Giants', 'Chicago White Sox', 'Chicago Cubs', 'Chicago Cubs', 'Pittsburgh Pirates', 'Philadelphia Athletics', 'Philadelphia Athletics', 'Boston Red Sox', 'Philadelphia Athletics', 'Boston Braves', 'Boston Red Sox', 'Boston Red Sox', 'Chicago White Sox', 'Boston Red Sox', 'Cincinnati Reds', 'Cleveland Indians', 'New York Giants', 'New York Giants', 'New York Yankees', 'Washington Senators', 'Pittsburgh Pirates', 'St. Louis Cardinals', 'New York Yankees', 'New York Yankees', 'Philadelphia Athletics', 'Philadelphia Athletics', 'St. Louis Cardinals', 'New York Yankees', 'New York Giants', 'St. Louis Cardinals', 'Detroit Tigers', 'New York Yankees', 'New York Yankees', 'New York Yankees', 'New York Yankees', 'Cincinnati Reds', 'New York Yankees', 'St. Louis Cardinals', 'New York Yankees', 'St. Louis Cardinals', 'Detroit Tigers', 'St. Louis Cardinals', 'New York Yankees', 'Cleveland Indians', 'New York Yankees', 'New York Yankees']
players_details, players_name = [], []
for each_player in players:
if not(each_player in players_name):
players_name = players_name + [each_player]
players_details = players_details + [[each_player, 1]]
else:
for index in range(len(players_details)):
if players_details[index][0] == each_player:
players_details[index][1] = players_details[index][1]+1
for each in players_details:
print '{} : {}'.format(*each)
Result:
Boston Americans : 1
New York Giants : 4
Chicago White Sox : 2
Chicago Cubs : 2
Pittsburgh Pirates : 2
Philadelphia Athletics : 5
Boston Red Sox : 4
Boston Braves : 1
Cincinnati Reds : 2
Cleveland Indians : 2
New York Yankees : 13
Washington Senators : 1
St. Louis Cardinals : 6
Detroit Tigers : 2