Python Forum
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
analyze list
#1
hi don't know how to change my text to ltr, sorry.
I'm new to python - but not to programming
I'm taking as my 1st project a lottery predictor based on previous results.
My lottery is picking 6 unique numbers between 1 - 37, I have a csv file of previous results.
I've divided the numbers into 4 groups:
1odd low: 1 3 5 7 9 11 13 15 17 19
2odd high: 21 23 25 27 29 31 33 35 37
3even low: 2 4 6 8 10 12 14 16 18
4even high: 20 22 24 26 28 30 32 34 36
What would be the best way to replace
the 6 digits by their group
eg. 6 17 18 25 27 35 would be 3 1 3 2 2 2

Hope this post is clear
thanks David
Reply
#2
if groups are in lists, you can find group by:
if number in group:
    ...
Reply
#3
Hi how do I change my default settings .
All my message box texts are right aligned because I'm living in Israel and Hebrew is a rtl language.
How do I change to English ltr.
Thanks Larz for your reply, put me on the path.
Could you tell me if the below code is the best way to do this or if I've used a sledge hammer to crack a nut.
import csv
import itertools
# the 37 numbers in the lottery are divided into 4 groups - odd low,
# odd high, even low and even high.
odd_low_set = {'1', '3', '5', '7', '9', '11', '13', '15', '17', '19'}
odd_high_set = {'21', '23', '25', '27', '29', '31', '33', '35', '37'}
even_low_set = {'2', '4', '6', '8', '10', '12', '14', '16', '18'}
even_high_set = {'20', '22', '24', '26', '28', '30', '32', '34', '36'}
with open('lotto-0807-1218.csv', newline='') as myFile:
     csv_reader = csv.reader(myFile, delimiter=',')
     # testing only, takes sample (3 rows) from the
     # 1,000 previous lotter results.
     for row in itertools.islice(csv_reader, 3):
       row_set = set(row[2:8])
    #   Create cnt_lst - a list of 4 items for each row - to see how 
    #   the six numbers in the row are divided between the above groups. 
       cnt_lst = [] 
       num =  len(set(row_set).intersection(odd_low_set))
       cnt_lst.append(num) 
       num =  len(set(row_set).intersection(odd_high_set))
       cnt_lst.append(num)
       num =  len(set(row_set).intersection(even_low_set))
       cnt_lst.append(num)
       num =  len(set(row_set).intersection(even_high_set))
       cnt_lst.append(num)
       print (cnt_lst)
The above code works, not sure it's the best way.
Input:
3083 11-12-18 15 21 23 27 36 37 3 0 0
3082 08-12-18 8 11 13 18 25 31 6 0 0
3081 04-12-18 1 3 7 9 15 22 2 0 0
Output:
[1, 4, 0, 1]
[2, 2, 2, 0]
[5, 0, 0, 1]
Reply
#4
you can use a function to create your lists:
def make_list(lmin, lmax):
    return [str(x) for x in range(lmin, lmax+2, 2)]

def test_make_list():
    odd_low_set = make_list(1, 19)
    print(f'odd_low_set: {odd_low_set}')
    odd_high_set = make_list(21, 37)
    print(f'odd_high_set: {odd_high_set}')
    even_low_set = make_list(2, 18)
    print(f'even_low_set: {even_low_set}')
    even_high_set = make_list(20, 36)
    print(f'even_high_set: {even_high_set}')

test_make_list()
results:
Output:
odd_low_set: ['1', '3', '5', '7', '9', '11', '13', '15', '17', '19'] odd_high_set: ['21', '23', '25', '27', '29', '31', '33', '35', '37'] even_low_set: ['2', '4', '6', '8', '10', '12', '14', '16', '18'] even_high_set: ['20', '22', '24', '26', '28', '30', '32', '34', '36']
I'll look at the rest in a bit
Reply
#5
(Dec-17-2018, 08:00 PM)davidm Wrote: hi don't know how to change my text to ltr, sorry.
I'm new to python - but not to programming
I'm taking as my 1st project a lottery predictor based on previous results.
My lottery is picking 6 unique numbers between 1 - 37, I have a csv file of previous results.
I've divided the numbers into 4 groups:
1odd low: 1 3 5 7 9 11 13 15 17 19
2odd high: 21 23 25 27 29 31 33 35 37
3even low: 2 4 6 8 10 12 14 16 18
4even high: 20 22 24 26 28 30 32 34 36
What would be the best way to replace
the 6 digits by their group
eg. 6 17 18 25 27 35 would be 3 1 3 2 2 2

Hope this post is clear
thanks David

Do you have the full source code of this project of yours? Can it be expanded for 49 numbers to pick from?
Reply
#6
pythonflea: Are you aware that the post you are responding to is over 2 years old?
It's possible, but quite unlikely that you will receive a response from the member,
They last visited several months ago.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get image from PI camera and analyze it korenron 0 1,124 Apr-28-2022, 06:49 AM
Last Post: korenron

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020