Python Forum
Extracting random word from list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extracting random word from list
#11
Assuming you are copying that to your program and not writing it out, as well as {} separating your "sets", and | separating your words you could just do
text = '''
{{howdy|hey|hey there|heyyy|hi cutey|hi there =)|sup|heyy|hey hey|heyyy|hiya|heya|heyyyy|hello there|hey babes|hey sexy|hey heyy|hi there}{..|.|,|...} {thanks|thnx|thank you|ty} {4|for} the {follow|add}{...|.|..} {whats up|what's up|what is up|what you up to|what u up to|what ya up to|how ya doing|how you dhow ya doin|how you doin|whats going on|what is going on|what's going on|what is goin on|whats goin on|what's goin on|how are ya|how are you|how are u}{?|??|???} {nm|not much|chilling|chillin|relaxing|relaxin|hanging out|hangin out|chillin out|chilling out|lounging out|coolin out} {here|over here}{.|,} {txt me|t xt me|tx t me|t.xt me|tx.t me|t.x.t me|text me|t ext me|te xt me|tex t me|t.ext me|te.xt me|tex.t me}{...|} {i am|im|i'm} {downright|flat out|terribly|extremely|really|super|absolutely|truly} bored{.|..|...} %s {..|....|..}
'''
for element in text.split('}'):
    print(element.split('|'))
Output:
['\n{{howdy', 'hey', 'hey there', 'heyyy', 'hi cutey', 'hi there =)', 'sup', 'heyy', 'hey hey', 'heyyy', 'hiya', 'heya', 'heyyyy', 'hello there', 'hey babes', 'hey sexy', 'hey heyy', 'hi there'] ['{..', '.', ',', '...'] [' {thanks', 'thnx', 'thank you', 'ty'] [' {4', 'for'] [' the {follow', 'add'] ['{...', '.', '..'] [' {whats up', "what's up", 'what is up', 'what you up to', 'what u up to', 'what ya up to', 'how ya doing', 'how you dhow ya doin', 'how you doin', 'whats going on', 'what is going on', "what's going on", 'what is goin on', 'whats goin on', "what's goin on", 'how are ya', 'how are you', 'how are u'] ['{?', '??', '???'] [' {nm', 'not much', 'chilling', 'chillin', 'relaxing', 'relaxin', 'hanging out', 'hangin out', 'chillin out', 'chilling out', 'lounging out', 'coolin out'] [' {here', 'over here'] ['{.', ','] [' {txt me', 't xt me', 'tx t me', 't.xt me', 'tx.t me', 't.x.t me', 'text me', 't ext me', 'te xt me', 'tex t me', 't.ext me', 'te.xt me', 'tex.t me'] ['{...', ''] [' {i am', 'im', "i'm"] [' {downright', 'flat out', 'terribly', 'extremely', 'really', 'super', 'absolutely', 'truly'] [' bored{.', '..', '...'] [' %s {..', '....', '..'] ['\n']
and yes it would need a little customizing
Recommended Tutorials:
Reply
#12
Still doesn't work. I'm about to just abandon that portion of the project. Nevertheless, I have one other issue here; do you happen to know why var1 won't show up in the entry box, yet it shows up perfectly fine in the shell? (If you're running the program, enter a few fruit names)
from tkinter import *
import random
import re
import secrets

class Application(Frame):

    def __init__(self, master):
        Frame.__init__(self, master)
        self.grid()
        self.create_widgets()
    def create_widgets(self):
        self.instruction = Label(self, text = "Enter Jumbo")
        self.instruction.grid(row = 0, column=0, columnspan = 3, sticky = W)

        self.text = Text(self, width = 35, height =5, wrap = WORD)
        self.text.grid(row =1, column=1, sticky = W)

        self.submit_button = Button(self, text = "Submit", command = self.reveal)
        self.submit_button.grid(row = 2, column = 0, sticky =W)

        self.text1 = Text(self, width = 35, height =5, wrap = WORD)
        self.text1.grid(row = 3, column =0, columnspan = 2, sticky=W)
    def reveal(self):
        content = self.text.get("1.0", "end-1c")
        answer = str(content)
        ggg = answer.split(" ")
    
        var1 = random.choice(ggg)
        
        print (content)
        print (answer)
        print (ggg)
        print (var1)

        self.text1.insert(3.0, "my favoite fruit is:", var1)
        
root = Tk()
root.title("practice")
root.geometry("450x250")
app = Application(root)

root.mainloop()
Reply
#13
you need to do
self.text1.insert(3.0, "my favoite fruit is: {}".format(var1))
As for the previous, you are going to probably have to make your own parser as its mostly rubbush input.
Recommended Tutorials:
Reply
#14
(nevermind, Ive been at it too long today) Thank you! I got it !!!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Sample random, unique string pairs from a list without repetitions walterwhite 1 457 Nov-19-2023, 10:07 PM
Last Post: deanhystad
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,221 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  List of random numbers astral_travel 17 2,715 Dec-02-2022, 10:37 PM
Last Post: deanhystad
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,521 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  For Word, Count in List (Counts.Items()) new_coder_231013 6 2,597 Jul-21-2022, 02:51 PM
Last Post: new_coder_231013
  find some word in text list file and a bit change to them RolanRoll 3 1,533 Jun-27-2022, 01:36 AM
Last Post: RolanRoll
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,508 Aug-12-2021, 04:25 PM
Last Post: palladium
  Extracting Elements From A Website List knight2000 2 2,273 Jul-20-2021, 10:38 AM
Last Post: knight2000
  Unable to use random.choice(list) in async method spacedog 4 3,442 Apr-29-2021, 04:08 PM
Last Post: spacedog
Thumbs Down extracting data/strings from Word doc mikkelibsen 1 1,926 Feb-10-2021, 11:06 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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