OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

string indices must be integers, not 'str' [duplicate]

  • Thread starter Thread starter kshitij bramhecha
  • Start date Start date
K

kshitij bramhecha

Guest
I am making a python code to get required details from json file. So while trying to get data I'm getting error "TypeError: string indices must be integers, not 'str'".

here is the code -

Code:
stats_to_check = ['points', 'three_points_made', 'three_points_attempted', 'rebounds', 'assists', 'steals', 'blocks']

for team in ['home', 'away']:
    for player in data['doc'][0]['data']['match']['teams'][team]['players']:
        for stats in stats_to_check:
            if stats in player['stats']:  
                player_stats = player['stats']
                highest_stat = find_highest_stat(player_stats)  # find_highest_stat expects a list
                if highest_stat['value'] > filtered_data['teams'][team]['game_leaders'][stats.upper()]['value']:
                    filtered_data['teams'][team]['game_leaders'][stats.upper()] = {
                        'player': player['name'],
                        'value': highest_stat['value']
<p>I am making a python code to get required details from json file.
So while trying to get data I'm getting error "TypeError: string indices must be integers, not 'str'".</p>
<p>here is the code -</p>
<pre><code>stats_to_check = ['points', 'three_points_made', 'three_points_attempted', 'rebounds', 'assists', 'steals', 'blocks']

for team in ['home', 'away']:
for player in data['doc'][0]['data']['match']['teams'][team]['players']:
for stats in stats_to_check:
if stats in player['stats']:
player_stats = player['stats']
highest_stat = find_highest_stat(player_stats) # find_highest_stat expects a list
if highest_stat['value'] > filtered_data['teams'][team]['game_leaders'][stats.upper()]['value']:
filtered_data['teams'][team]['game_leaders'][stats.upper()] = {
'player': player['name'],
'value': highest_stat['value']
</code></pre>
 

Latest posts

Online statistics

Members online
0
Guests online
2
Total visitors
2
Top