0

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)
Remi Guan
  • 21,506
  • 17
  • 64
  • 87
mruss24
  • 367
  • 2
  • 6
  • 14
  • Your example doesn't run. It helps a lot if you have can indicate the *actual* problem where you are stuck? For example, do you have problems running the above code? Or do you not know how to get a random element from a list (hint: look at the random module)? –  Oct 11 '15 at 10:03
  • This is quite a good link for choosing a random item from a list: https://stackoverflow.com/questions/306400/how-do-i-randomly-select-an-item-from-a-list-using-python –  Oct 11 '15 at 10:04
  • You should use http://pandas.pydata.org/pandas-docs/stable/dsintro.html#dataframe for this purpose as more convenient a clear way of managing datasets. – outoftime Oct 11 '15 at 10:12

2 Answers2

3

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

sauerburger
  • 4,569
  • 4
  • 31
  • 42
2
import random

player = random.choice(players)

player.search()...
Mate Hegedus
  • 2,887
  • 1
  • 19
  • 30