Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List creator
#1
Just a quick question from a beginner. How would I put a list of 30+ names randomly into 3+ different columns until there are no more names.
Reply
#2
some psuedo code:
  • download list of names (csv) from :http://www.quietaffiliate.com/free-first...v-and-sql/
  • import random
  • import csv
  • random_names =
  • load csv name data (downloaded file) using csv.reader
  • split csv data into list
  • randomly select 30 names from dsv list and append to random_names
  • print using format statement like '{}\t{}\t[}tn'
Reply
#3
Use shuffle from the random package to randomize the list. Then you can just feed it into the different columns. That's if you want an even number of names in each column. If you want to fill them with random lengths, the randrange function from random could choose a different column for each name.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#4
(Sep-04-2017, 04:09 PM)Larz60+ Wrote: some psuedo code:
  • download list of names (csv) from :http://www.quietaffiliate.com/free-first...v-and-sql/
  • import random
  • import csv
  • random_names =
  • load csv name data (downloaded file) using csv.reader
  • split csv data into list
  • randomly select 30 names from dsv list and append to random_names
  • print using format statement like '{}\t{}\t[}tn'

I already have the names to input. Im trying to create a schedule maker. I can generate days off and stuff like that but i still don't know how to put the pre entered names into there columns.

I want it to look something like

Main------------End----------------Middle
james- mon,fri--jack- tue, wed-----frank- sat,sun
alex- tue, fri--noelle-, thur,fri--kai- mon,tue

Any ideas how i should go about this?
Reply
#5
csv documentation: https://docs.python.org/3/library/csv.html
random documentation: https://docs.python.org/3/library/random.html
list documentation: https://docs.python.org/3/tutorial/datastructures.html

here's a starter:
import csv

def read_csv_data(filename):
    try:
        buffer = None
        with open(filename) as csvfile:
            buffer = csv.reader(csvfile, delimiter=',')
            for row in buffer:
                print(row)
    except csv.Error:
        print(f'Error reading {filename}')

if __name__ == '__main__':
    read_csv_data('CSV_Database_of_First_Names.csv')
download the namefile from the url I gave you before.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Wanted to tag azure resources with creator name raham3406 0 1,447 Apr-25-2021, 02:24 PM
Last Post: raham3406
  Random Expression Creator SheeppOSU 2 2,478 Nov-01-2018, 11:08 PM
Last Post: wavic

Forum Jump:

User Panel Messages

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