Reputation: 1
from this list, from which I shuffle:
RotationSpeedArray = [4,6,8,10] #in Hz
random.shuffle(RotationSpeedArray)
I try to call it from one specific number at a time,
print RotationSpeedArray[0]
print RotationSpeedArray[1]
print RotationSpeedArray[2]
print RotationSpeedArray[3]
but whenever I do I get this:
#an actual empty space
[
6
,
The code from this is part is meant to draw a figure and rotate it. We want to do so a different speeds, so that's why we created a list from which it takes one of those rotation speeds and uses it. The figure actually moves for each trial at a different speed, so the process of taking one value at a time works. I just don't get why whenever I ask to show me each value of the list, it does this.
I hope this is sufficiently clear; please don't hesitate asking me any question.
Upvotes: 0
Views: 53
Reputation: 16162
I'm having no problems. Are you sure you're not surrounding converting your list to a string somewhere down the line?? It's treating RotationSpeedArray as a string, which is why I ask.
random.shuffle will throw a TypeError if you had put quotes around the list, so I'm assuming there is code you're not showing us somewhere past that which is converting it to a string?
import random
RotationSpeedArray = [4,6,8,10] #in Hz
random.shuffle(RotationSpeedArray)
# the problem is happening here
print(RotationSpeedArray[0])
print(RotationSpeedArray[1])
print(RotationSpeedArray[2])
print(RotationSpeedArray[3])
print(RotationSpeedArray)
# To demonstrate your particular issue, if we convert the list to a string
# we get the same problem you're having
StringArray = str(RotationSpeedArray)
print(StringArray[0])
print(StringArray[1])
print(StringArray[2])
print(StringArray[3])
print(StringArray)
Output:
10
6
4
8
[10, 6, 4, 8]
[
1
0
,
[10, 6, 4, 8]
Upvotes: 4