Skip to content

Instantly share code, notes, and snippets.

@thevar1able
Created November 23, 2021 18:31
Show Gist options
  • Save thevar1able/932f4e4311887bd117bf3f39903aa8b0 to your computer and use it in GitHub Desktop.
Save thevar1able/932f4e4311887bd117bf3f39903aa8b0 to your computer and use it in GitHub Desktop.
"""
1. Create a list of first names
2. Create a list of last names
3. Combine them randomly into a list of 100 full names
4. Insert into sqlite table "Names"
"""
import sqlite3
import random
# Create a list of first names
first_names = ['John', 'Jane', 'Corey', 'Travis', 'Dave', 'Kurt', 'Neil', 'Sam', 'Steve', 'Tom', 'James', 'Robert', 'Michael', 'Charles', 'Joe', 'Mary', 'Maggie', 'Nicole', 'Patricia', 'Linda', 'Barbara', 'Elizabeth', 'Laura', 'Jennifer', 'Maria']
# Create a list of last names
last_names = ['Smith', 'Doe', 'Jenkins', 'Robinson', 'Davis', 'Stuart', 'Jefferson', 'Jacobs', 'Wright', 'Patterson', 'Wilks', 'Arnold', 'Johnson', 'Williams', 'Jones', 'Brown', 'Davis', 'Miller', 'Wilson', 'Moore', 'Taylor', 'Anderson', 'Thomas', 'Jackson', 'White', 'Harris', 'Martin']
# Create a list of 100 full names
full_names = []
for i in range(100):
full_names.append(random.choice(first_names) + " " + random.choice(last_names))
# Connect to sqlite database
conn = sqlite3.connect('week2_assignment.db')
# Create cursor object
c = conn.cursor()
# Insert full names into table
c.execute("INSERT INTO Names VALUES (?)", (full_names[0],))
# Commit changes
conn.commit()
# Close connection
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment