Python Forum
How to pick random entries of stock prices?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to pick random entries of stock prices?
#2
Something like that?
victor ~ $ ptpython
>>> import random, datetime

>>> months = {datetime.date(2017, month, 1).strftime('%B'): month for month in range(1, 13)}

>>> carousel = iter(months)

>>> num = months[random.choice(list(months.keys()))]

>>> for i in range(num - 1):
...     next(carousel)

>>> while True:
...     try:
...         print(months[next(carousel)])
...     except StopIteration:
...         break
10
11
12
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
RE: How to pick random entries of stock prices? - by wavic - Jul-16-2017, 09:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pick a line in a plot with matplotlib Romain 3 5,749 Feb-28-2023, 11:56 AM
Last Post: get2sid
  Learning indexing with python, pick dates dervast 1 1,806 Jul-11-2019, 07:29 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020