On 04/07/2014 06:44, Mitesh H. Budhabhatti wrote:
Hello Mario,
I think if you are facing the problem with shuffle, can the below
solution help:
import random
import csv
f = open('D:\\py.csv', 'r', newline='', encoding='utf8')
csvreader = csv.reader(f)
l = [row for row in csvreader] #we get
Mario Py wrote:
OK, I'm finally getting closer.
Code bellow (looks like) works if I comment out shuffle part
But I need it to shuffle so I get random picked words.
How do I get shuffle part to work?
csv.reader() returns an iterator, i. e. an object that dynamically
calculates new rows
Slight aside, it appears from cell# that you're in prison. Is that the
case, or did you actually mean mobile phone number? :)
Sorry for that.. I use gmail and I just missed to remove my signature.
Replying here for the first time and learning etiquette.
On 7/4/2014 1:21 AM, Peter Otten wrote:
data = list(data)
shuffle(data)
Peter, Mitesh and Alan,
Thank you for your help! And thank you for explaining details.
Now I understand why it worked in my previous (*.TXT) version since it
was already as list.
Thanks again, program works great
OK, I'm finally getting closer.
Code bellow (looks like) works if I comment out shuffle part
But I need it to shuffle so I get random picked words.
How do I get shuffle part to work?
from random import shuffle
import csv
print('Write translation of Slovene word ')
print()
Windows 7, Python 3.4.0
I have a simple translation refresher program that works.
For input I'm using TXT file, (prevedi.txt) words in it are separated by
coma that I'm editing, adding manually. (adding new 'refresher' words as
needed) And program works:
from random import shuffle
Hello Mario,
I think if you are facing the problem with shuffle, can the below solution
help:
import random
import csv
f = open('D:\\py.csv', 'r', newline='', encoding='utf8')
csvreader = csv.reader(f)
l = [row for row in csvreader] #we get rows in the file as a list using
list comprehension
On 04/07/14 02:07, Mario Py wrote:
How do I get shuffle part to work?
look at the random module.
there are several options in there, I think random.shuffle()
is your best bet.
hth
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/