0

I am very new to python and am learning it just for fun. I am attempting to use it for a small application that shuffles a string list. I need to get a list of about 50 last names in a random order. I tried doing

items = [thing1, thing2, thing3]
random.shuffle(items)

but it tells me i need to define every item in the list. I know there has got to be a way to do this, i just havent figured it out yet. Any suggestions?

3
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by aloishis89
0

I am very new to python and am learning it just for fun. I am attempting to use it for a small application that shuffles a string list. I need to get a list of about 50 last names in a random order. I tried doing

items = [thing1, thing2, thing3]
random.shuffle(items)

but it tells me i need to define every item in the list. I know there has got to be a way to do this, i just havent figured it out yet. Any suggestions?

>>> items = ['thing1', 'thing2', 'thing3']
>>> import random
>>> random.shuffle(items)
>>> items
['thing3', 'thing1', 'thing2']
>>>

Without the quotes Python thinks they are objects.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.