hey I was wondering is there a way to make a program that would type out a different sentence from a list every minute of discord? if there is how would I go about doing it on python?
If it can be conceived, it can be realized. That’s the general mantra in programming. Anything is possible, if… (I’ll stop here).
First we need a method to scramble the list each time we generate a new sentence. A few weeks ago I wrote a snippet in another topic along those lines…
Python has a sleep function that let’s us build in a delay of some duration in seconds.
>>> from time import sleep
>>> my_dict = { 'key' + str(x+1): 0 for x in range(10) }
>>> for key in my_dict:
print (key, my_dict[key])
sleep(5)
key7 0
key6 0
key3 0
key5 0
key10 0
key9 0
key2 0
key4 0
key8 0
key1 0
>>>
The above printed a new key:value pair at five second intervals.
Now we just need a list of words and loop that iterates once a minute and runs the shuffle method each time to generate a new sentence.
Note that the method illustrated will not permit duplicates in the list. The following shuffle method permits duplicates…
from random import randrange
def shuffle(a_list):
z = list(range(len(a_list)))
y = []
while z:
y += [z.pop(randrange(len(z)))]
return [a_list[x][::-1] for x in y]
1 Like