mruss24
mruss24

Reputation: 367

How can I create a list of players in python

I have a list of players with the following attributes - assetId maxBid minPrice maxPrice

How can I create a list in Python and pick one player at random an apply it to a search function.

I am looking to accomplish something like this :

players = []
players.append(13732, 8000, 9300, 9400) #John Terry
players.append(165580, 2400, 3000, 3100) #Diego Alves
for player in players:
    items = fut.searchAuctions('player', 
                               assetId=player.assetId,
                               max_buy=player.maxBid)

Upvotes: 0

Views: 2903

Answers (2)

sauerburger
sauerburger

Reputation: 5148

I suggest you create a player class:

class Player:
  def __init__(self, assetId, maxBid, minPrice, maxPrice):
    self.assetId = assetId
    self.maxBid = maxBid
    self.minPrice = minPrice
    self.maxPrice = maxPrice

this way you can create new objects with player = Player(13732, 8000, 9300,9400) Your list would the be created with

players = []
players.append(Player(13732, 8000, 9300,9400))
players.append(Player(165580, 2400, 3000, 3100))

to select a player randomly you can do

import random
randomPlayer = random.choice(players)

now you can use randomPlayer and its attributes e.g. randomPlayer.assetId and pass it to your search

Upvotes: 3

Mate Hegedus
Mate Hegedus

Reputation: 2905

import random

player = random.choice(players)

player.search()...

Upvotes: 2

Related Questions