Reputation: 689
I have two variables that I am trying to make 1 variable.
import requests
from pprint import pprint
req = requests.get('https://www.fantasylabs.com/api/sportevents/4/02_03_2018/team-ratings/')
data = req.json()
for event in data:
ed = event['EventDetails']
prop = ed['Properties']
home = prop['HomeTeamShort']
away = prop['VisitorTeamShort']
teams = home, away
print(home,away)
Results:
PHI OTT
MTL ANA
WPG COL
NYI CLB
NJD PIT
FLA DET
BUF STL
BOS TOR
NAS NYR
DAL MIN
CGY CHI
VAN TB
LA ARI
With the teams
variable above i would like to make them 1. How do i make it so both names are in the teams variable?
Upvotes: 3
Views: 140
Reputation: 24261
As is, teams
has this shape: (home, away)
.
You could use a join
statement to print the elements of team
as a single string:
print(" ".join(teams))
>>>PHI OTT
Upvotes: 4
Reputation: 1682
I would create a dictionary for a little bit of hierarchy.
teams = {"home": home, "away": away}
This way you could reference them with the same variable, but they maintain their distinctiveness.
print(teams["home"] + " vs. " + teams["away"])
Upvotes: 2
Reputation: 2750
If you just want to concatenate the two values, and not access them separately, then you can just say
teams = home + ' ' + away
Upvotes: 1