Oct-16-2016, 05:15 PM
Hi
In the sample program I have attached below I first use
I can add that I use Python 3.5 (32-bit) through PyCharm Professional 2016.2.3 on Windows 10 64-bit.
I look forward to hear from you!
Best regards,
Henrik R.
Here is the whole program:
In the sample program I have attached below I first use
SelectedTargets = random.sample(TargetPool, NoOfTargetsToSelect)to draw out some of the items from a list. Then I want to shuffle that list with
Sessions2 = random.shuffle(SelectedTargets). But that gives me an empty list containing only "None". Why?
I can add that I use Python 3.5 (32-bit) through PyCharm Professional 2016.2.3 on Windows 10 64-bit.
I look forward to hear from you!
Best regards,
Henrik R.
Here is the whole program:
import random TargetPoolFile = open('TestPool.txt', 'r') TargetPool = TargetPoolFile.readlines() NoOfTargetsInPool = len(TargetPool) print("No. of targets in Pool:", NoOfTargetsInPool) NoOfTargetsToSelect = 5 print("No. of targets to select:", NoOfTargetsToSelect) SelectedTargets = random.sample(TargetPool, NoOfTargetsToSelect) print(SelectedTargets) # Until here: It works # According to https://docs.python.org/3.5/library/random.html: # random.shuffle(list) should rearrange the order of the items on # the list, but instead it gives an empty list - containing "None": Sessions2 = random.shuffle(SelectedTargets) print(Sessions2)Here is the contents of the input-file 'TestPool.txt':
1 EUR/USD
2 AUD/USD
3 EUR/CHF
4 EUR/GBP
5 EUR/JPY
6 GBP/EUR
7 GBP/USD
8 USD/CAD
9 USD/CHF
10 USD/JPY
11 CAD/CHF
12 CAD/JPY
13 CHF/JPY
14 EUR/CAD
15 EUR/SGD
16 EUR/ZAR
17 GBP/CAD
18 GBP/CHF
19 GBP/JPY
20 GBP/SGD
2 AUD/USD
3 EUR/CHF
4 EUR/GBP
5 EUR/JPY
6 GBP/EUR
7 GBP/USD
8 USD/CAD
9 USD/CHF
10 USD/JPY
11 CAD/CHF
12 CAD/JPY
13 CHF/JPY
14 EUR/CAD
15 EUR/SGD
16 EUR/ZAR
17 GBP/CAD
18 GBP/CHF
19 GBP/JPY
20 GBP/SGD