Python Forum
Generate a string of words for multiple lists of words in txt files in order.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Generate a string of words for multiple lists of words in txt files in order.
#1
Ok, so I want to make something that takes some text files with lists of words in them and outputs every combination of those words in order. For example:
If I had a txt file with the English dictionary, one with the names of the days and months, one with every number 1-99 and finally a list of symbols, I want the program to output a string of words in that order, ex: liveTuesday10@, wouldDecember7*, softNovember85#, etc etc. But it would only give words in that order (dictionary, day/month, number, symbol), not like 65Friday£hippo. Is it possible? If so please show me how.
Reply
#2
what have you tried so far?
Reply
#3
Hello mate,

Import the random library and assign a random number to a variable for each of the text files, read in the text files and then use the random number as an index point for each list.

It would be easier to do it from a csv using numpy - EG:
import numpy as np
list_of_words = np.genfromtxt('words.csv',delimiter = ",")
You can then use the random library to give a variable a random number:

import random
random_number = random.randint(1, 10)
And then you can use that to choose the item from the list:
print(list_of_words[random_number])
If you have a varied number of items on each list you could also do:
import numpy as np
import random
list_of_words = np.genfromtxt('words.csv',delimiter = ",")
x = int(len(list_of_words))
random_number = random.randint(1, x)
You could then make a random order generator by using random number generation and a series of if statements:
#random number made x
#random number made y
#random number made z

if x > y and x > z:
    if y > z:
        print (list[x] + list[y] + list[z])
    if z > y:
        print(list[x] + list[z] + list[y])
#and so on
while dad_has_cigs == True:
    happiness = True
    if dad_has_cigs == False:
    print("Dad come home!")
    happiness = not happiness
    break
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python convert multiple files to multiple lists MCL169 6 1,535 Nov-25-2023, 05:31 AM
Last Post: Iqratech
  find and group similar words with re? cartonics 4 724 Oct-27-2023, 05:36 PM
Last Post: deanhystad
  Function to count words in a list up to and including Sam Oldman45 15 6,556 Sep-08-2023, 01:10 PM
Last Post: Pedroski55
  Form that puts diacritics on the words in the text Melcu54 13 1,467 Aug-22-2023, 07:07 AM
Last Post: Pedroski55
  splitting file into multiple files by searching for string AlphaInc 2 890 Jul-01-2023, 10:35 PM
Last Post: Pedroski55
  docx insert words of previuos paragraph on next paragraph in the same position ctrldan 7 1,242 Jun-20-2023, 10:26 PM
Last Post: Pedroski55
  Pulling Specifics Words/Numbers from String bigpapa 2 752 May-01-2023, 07:22 PM
Last Post: bigpapa
  Generate lists of devices and partitions from /proc/partitions? DachshundDigital 1 765 Feb-28-2023, 10:55 PM
Last Post: deanhystad
  Merging multiple csv files with same X,Y,Z in each Auz_Pete 3 1,152 Feb-21-2023, 04:21 AM
Last Post: Auz_Pete
  unittest generates multiple files for each of my test case, how do I change to 1 file zsousa 0 957 Feb-15-2023, 05:34 PM
Last Post: zsousa

Forum Jump:

User Panel Messages

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