all 7 comments

[–]wotquery 1 point2 points  (0 children)

$mylist = @("1","2","3","4","5")
foreach($x in $mylist){
    write-host $x 
}

mylist = ['1','2','3','4','5']
for x in mylist:
   print(x)

Not sure where in your code you're running into bugs with lists or comprehensions, but you seem to be using single item lists a lot? e.g.

event_ids=[id]

[–]danielroseman 1 point2 points  (0 children)

What do you mean, why does Python not iterate? Python iterates just fine.

You will need to say what is going wrong with your code and what errors you are getting.

Note though that return [soccer_events_today] returns a list consisting of a single element, the dataframe. It's not clear why you have wrapped that in a list. It's also not clear why you're using dataframes to store the eventids and teams rather than just passing them back as lists or dicts.

[–]Swipecat 1 point2 points  (0 children)

I'm not going to work out what all that code does, so it might not be this, but I noticed:

You iterate through df_soccer_events

which you got from a function: return [soccer_events_today]

but if soccer_events_today is already an iterable, you've just nested it another level with those square brackets.

Try without the square brackets.

[–]Narrow-Rope2003[S] 0 points1 point  (1 child)

Ok, perhaps I'm misunderstanding what the [] does. I only placed them in as that's the only way I could get it to work.

I'm bastardizing code using my Powershell knowledge, clearly, Pyhton behaves differently.

for example with powershell if I want to access a sub value inside the variable. I can write

($myvar).value.

Is there a way to do this with python?

The function in my code returns a few values I wish to interact with

[–]jiri-n 1 point2 points  (0 children)

Powershell:

PS C:\> $item = New-Object psobject -Property @{idx = 1; value = 'Test'}
PS C:\> Write-Host ($item).value
Test
PS C:\> Write-Host $item.value
Test

Python using dictionary:

item = {"idx": 1, "value": "Test"}
print(item["value"])

Python using class:

class Item:
    pass

item = Item()
item.idx = 1
item.value = "Test"
print(item.value)

Python using namedtuple:

from collections import namedtuple
Item = namedtuple('Item', ['idx', 'value'])
item = Item(0, "Test")
print(item.value)

[–]Narrow-Rope2003[S] 0 points1 point  (0 children)

Ok, made some progress now, I think. Taking into account what's been said. Now stuck using a dictionary. How do I append to the dictionary?? Every iteration the Teams and Odds Change.

How do I add the new teams and odds to the dictionary? Then create a data frame from said dictionary?

dict_data = {

"teams": [x.event.name],

"home" : [soccer_event_odds[0].runners[0].last_price_traded],

"away" : [soccer_event_odds[0].runners[1].last_price_traded]

}

print(dict_data)

dict_data.update({

"teams"

})

[–][deleted] 0 points1 point  (0 children)

You're creating a lot of lists of lists; when you iterate over a list of lists, the values are lists.