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: [email protected], 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
  Search string in mutliple .gz files SARAOOF 10 891 Aug-26-2021, 01:47 PM
Last Post: SARAOOF
  Generate Multiple sql Files With csv inputs vkomarag 13 781 Aug-20-2021, 07:03 PM
Last Post: vkomarag
  Replace String in multiple text-files [SOLVED] AlphaInc 5 688 Aug-08-2021, 04:59 PM
Last Post: Axel_Erfurt
  Open and read multiple text files and match words kozaizsvemira 3 4,260 Jul-07-2021, 11:27 AM
Last Post: Larz60+
  Plotting Multiple files ! Helen_145 1 479 Jun-26-2021, 03:28 PM
Last Post: snippsat
  Create Dict from multiple Lists with duplicate Keys rhat398 10 936 Jun-26-2021, 11:12 AM
Last Post: Larz60+
  Reading Multiple text Files in pyhton Fatim 1 445 Jun-25-2021, 01:37 PM
Last Post: deanhystad
  Running script on multiple files Afrodizzyjack 1 701 May-14-2021, 10:49 PM
Last Post: Yoriz
  Better way to append frames from a video to multiple lists? Balaganesh 0 498 May-13-2021, 07:37 AM
Last Post: Balaganesh
  Repeating Words in MadLib [resolved] actual_satan 1 526 May-07-2021, 08:45 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

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