472,791 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,791 software developers and data experts.

seaching a list...

hi...

i'm playing with a test sample. i have somethhing like:
dog = mysql_get(.....)
Aug 10 '06 #1
4 1510
bruce wrote:
hi...

i'm playing with a test sample. i have somethhing like:
dog = mysql_get(.....)
.
.
.

such that 'dog' will be an 'AxB' array of data from the tbls
What's an "'AxB' array", do you mean a list of lists? If not, what
kind of object do you mean and what methods does it have?
>
furher in the test app, i'm going to have a list, foo:
foo = 'a','b','c','d'
That's a tuple, not a list.
>
i'm trying to determine what's the fastest way of searching through the
'dog' array/list of information for the 'foo' list.

should i essentially make dog into A lists, where each list is B elements,
or should it somehow combine all the elements/items in 'dog' into one large
list, and then search through that for the 'foo' list...
This really depends on what kind of searching you want to do, and what
kind of results you want.

If dog is a list of lists, and foo might occur as one of the sublists,
then you could do something like this:

try:
i = dog.index(foo)
except ValueError:
i = -1
>
also, in searching through google, i haven't come across the list.search
function..
That's because it doesn't exist.
so just how do i search a list to see if it contains a sublist...
One thing that can do this is the difflib.SequenceMatcher() class.
Read this: http://docs.python.org/lib/sequence-matcher.html

|>from difflib import SequenceMatcher
|>N = range(10)
|>M = range(3, 6)
|>s = SequenceMatcher(a=N, b=M)
|>c = len(M)
|>[i for i, j, n in s.get_matching_blocks() if n == c]
[3]
There may be better ways.
>
my real problem involves figuring out how to reduce the number of hits to
the db/tbl...
What?
>
thanks

ps. if this is confusing, i could provide psuedo-code to make it easier to
see...
Yes, please.
Peace,
~Simon

Aug 10 '06 #2
bruce wrote:
hi...

i'm playing with a test sample. i have somethhing like:
dog = mysql_get(.....)
.
.
.

such that 'dog' will be an 'AxB' array of data from the tbls

furher in the test app, i'm going to have a list, foo:
foo = 'a','b','c','d'

i'm trying to determine what's the fastest way of searching through the
'dog' array/list of information for the 'foo' list.

should i essentially make dog into A lists, where each list is B elements,
or should it somehow combine all the elements/items in 'dog' into one large
list, and then search through that for the 'foo' list...

also, in searching through google, i haven't come across the list.search
function.. so just how do i search a list to see if it contains a sublist...

my real problem involves figuring out how to reduce the number of hits to
the db/tbl...

thanks

ps. if this is confusing, i could provide psuedo-code to make it easier to
see...

You should use the database for what it is good at storing and searching
through data. Don't read all the data from a table and search through it.
Rather, create indexes on the table so that you can locate the data quickly
in the database by passing in something you are looking for and let the
database do the searching. I can promise you this will almost always be
faster and more flexible. Something like:

Assume the columns are called rownumber, c1, c2, c3, c4 and the table is
indexed on c1, c2, c3, and c4. This will happen almost instantly no matter
how many rows you are searching for.

select rownumber from database_table
where c1="a" and c2="b" and c3="c" and c5="d"

It takes one "hit" to the db/table to return the rowindex that matches.

-Larry Bates
Aug 10 '06 #3

bruce wrote:
hi larry...

thanks for the reply...

the issue i'm having is that i'm going to have to compare multiple rows of
information to the information in the db. so essentially i'd have to do a
hit to the db, for each row of information i want to compare if i did it
your way... (which was what i had thought about)

the issue of doing the string/list compare/search is that i can get
everything from the db with one call... i can then iterate through memory
for each of my row information that i'm searching to see if it exists in the
db...

memory searches should be faster than the network overhead, and the
associated multiple db calls...
(1) Don't top-post.
(2) Do as asked: supply some pseudo-code for comparing a row of query
information with a row extracted from your database -- whether you are
comparing on one/some/all columns and what type of comparison are vital
pieces of information. How many query rows? How many database rows?

Aug 11 '06 #4
At Thursday 10/8/2006 21:54, bruce wrote:
>the issue i'm having is that i'm going to have to compare multiple rows of
information to the information in the db. so essentially i'd have to do a
hit to the db, for each row of information i want to compare if i did it
your way... (which was what i had thought about)

the issue of doing the string/list compare/search is that i can get
everything from the db with one call... i can then iterate through memory
for each of my row information that i'm searching to see if it exists in the
db...

memory searches should be faster than the network overhead, and the
associated multiple db calls...
should... are you sure?
How many rows on the database? how many rows to compare? network overhead?
Do some timing/performance tests to evaluate that. Things aren't
always as you expect.

Gabriel Genellina
Softlab SRL

__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Aug 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: massimo | last post by:
Hey, I wrote this program which should take the numbers entered and sort them out. It doesn¹t matter what order, if decreasing or increasing. I guess I'm confused in the sorting part. Anyone...
8
by: yasaswi | last post by:
I am using field( substring( product_id, 1, 4 ), 'IR56', '1k09', '7a72', '6f22' ) > 0 in a where clause to select four different strings of same length. However I want to be able to search...
10
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy...
24
by: Robin Cole | last post by:
I'd like a code review if anyone has the time. The code implements a basic skip list library for generic use. I use the following header for debug macros: /* public.h - Public declarations and...
4
by: JS | last post by:
I have a file called test.c. There I create a pointer to a pcb struct: struct pcb {   void *(*start_routine) (void *);   void *arg;   jmp_buf state;   int    stack; }; ...
3
by: chellappa | last post by:
hi this simple sorting , but it not running...please correect error for sorting using pointer or linked list sorting , i did value sorting in linkedlist please correct error #include<stdio.h>...
0
by: drewy2k12 | last post by:
Heres the story, I have to create a doubly linked list for class, and i have no clue on how to do it, i can barely create a single linked list. It has to have both a head and a tail pointer, and...
10
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
0
by: Atos | last post by:
SINGLE-LINKED LIST Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.