#๐Ÿ”’ Weird Code behaviour

5 messages ยท Page 1 of 1 (latest)

topaz badge
#

for info in main_text.split('\n')[1:]:
    sub_info = info.split('\t')
    
    print(sub_info)
    info_dict[sub_info[0]] = {base_heading[sub_info.index(key)]:key for key in sub_info[1:]}
    ```

What this is doing is allocating the numbers in a list to a dictionary which describes what those numbers indicate. Here, base_heading is 
```py
base_heading = ['PLAYER', 'TEAM', 'GP', 'W', 'L', 'MIN', 'DRIVES', 'FGM', 'FGA', 'FG%', 'FTM', 'FTA',  'FT%', 'PTS', 'PTS%', 'PASS', 'PASS%', 'AST', 'AST%', 'TO', 'TOV%', 'PF', 'PF%']

So the problem here is that it misbehaves for a specifc column. As we can see:

['Jalen Williams', 'OKC', '60', '48', '12', '32.5', '13.3', '3.2', '6.7', '46.8', '1.7', '2.1', '79.7', '8.2', '61.7', '4.4', '33.0', '1.5', '10.9', '0.7', '5.0', '1.1', '8.1']
{'TEAM': 'OKC', 'GP': '60', 'W': '48', 'L': '12', 'MIN': '32.5', 'DRIVES': '13.3', 'FGM': '3.2', 'FGA': '6.7', 'FG%': '46.8', 'FTM': '1.7', 'FTA': '2.1', 'FT%': '79.7', 'PTS': '8.2', 'PTS%': '61.7', 'PASS': '4.4', 'PASS%': '33.0', 'AST': '1.5', 'AST%': '10.9', 'TO': '0.7', 'TOV%': '5.0', 'PF': '1.1', 'PF%': '8.1'}
['Deni Avdija', 'POR', '65', '31', '34', '29.3', '9.9', '2.0', '3.5', '56.4', '1.6', '2.0', '79.1', '5.7', '57.6', '4.4', '44.1', '1.0', '9.8', '0.8', '7.6', '1.0', '10.2']
{'TEAM': 'POR', 'GP': '65', 'W': '31', 'L': '34', 'MIN': '29.3', 'DRIVES': '9.9', 'FGM': '2.0', 'FGA': '3.5', 'FG%': '56.4', 'FTM': '1.6', 'FT%': '79.1', 'PTS': '5.7', 'PTS%': '57.6', 'PASS': '4.4', 'PASS%': '44.1', 'AST': '1.0', 'AST%': '9.8', 'TO': '0.8', 'TOV%': '7.6', 'PF%': '10.2'}

For somereason it decides to skip the PF on Deni Avidja's column and because of that it throws off the dictionary. This is even more weird because after 10.2, it's literally 1.0 but it decides to completely ignore it.

leaden sleetBOT
#

@topaz badge

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

topaz badge
#

!close

leaden sleetBOT
#
Python help channel closed with !close

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.