Questions tagged [reverse-lookup]

Many programming languages feature data structures where unique indexes are associated with a value. Reverse lookup is retrieving the index with which a given value is accessed.

47 questions
103
votes
7 answers

Does Java have a HashMap with reverse lookup?

I have data that is organized in kind of a "key-key" format, rather than "key-value". It's like a HashMap, but I will need O(1) lookup in both directions. Is there a name for this type of data structure, and is anything like this included in…
Kip
  • 107,154
  • 87
  • 232
  • 265
72
votes
13 answers

Using Python's list index() method on a list of tuples or objects?

Python's list type has an index() method that takes one parameter and returns the index of the first item in the list matching the parameter. For instance: >>> some_list = ["apple", "pear", "banana", "grape"] >>> some_list.index("pear") 1 >>>…
Ryan B. Lynch
  • 2,307
  • 3
  • 21
  • 21
11
votes
2 answers

DJANGO: How to list_display a reverse foreign key attribute?

I'm building a web app that tracks what library books a person checks out. I have the following models: class Person(models.Model): name = models.CharField(max_length=100) def __unicode__(self): return self.name class…
thedeepfield
  • 6,138
  • 25
  • 72
  • 107
7
votes
5 answers

Reverse IP lookup with PHP

In PHP is there a function to do a reverse lookup on a domain name to find out how many websites are hosted on the particular shared hosting server that domain name is hosted on. Or, a way to do this with PHP? Now, I'm already aware of the online…
Marcus
  • 4,400
  • 13
  • 48
  • 64
5
votes
5 answers

In python, how can you retrieve a key from a dictionary?

I have a hashable identifier for putting things in a dictionary: class identifier(): def __init__(self, d): self.my_dict = d self.my_frozenset = frozenset(d.items()) def __getitem__(self, item): return…
user
  • 7,123
  • 7
  • 48
  • 90
5
votes
1 answer

How to perform a reverse DNS lookup in Python?

Is there any way to do a reverse lookup using python, to check the list of websites sharing the same IP address in a shared hosting? Some web sites offer a tool for this purpose .
4m1nh4j1
  • 4,289
  • 16
  • 62
  • 104
4
votes
2 answers

how to efficiently use _set.all() in django?

Is there a way in django to do the following more efficiently when the number Entry objects is greater than 5000 entries? models.py class Entry(models.Model): user = models.TextField(db_column='User', blank=True) date =…
John Waller
  • 2,257
  • 4
  • 21
  • 26
4
votes
1 answer

Hash table reverse lookup to find smallest key

I had an interview question to search a hash table for a value and return the smallest key. My approach was to sort the hash table by key and iterate through it to find the key corresponding to searched value. I wrote this function in Python: def…
Ramya
  • 284
  • 2
  • 5
  • 18
4
votes
2 answers

How expensive is the "key" function of a Ruby hash?

I'm using a couple of Hashes where the values of some hashes are the key of others. I need to use key a couple of times to get the key for a value so that I can use it to access something in another hash. I was wondering what kind of a performance…
MarioDS
  • 12,895
  • 15
  • 65
  • 121
3
votes
0 answers

Performance: Database, Django, reverse lookup or direct?

I have 2 models. first contain 5000 objects. second contain 10M objects. class Follower(models.Model): username = models.CharField( _("username"), max_length=250, db_index=True) class Influencer(models.Model): username =…
flice com
  • 125
  • 7
3
votes
2 answers

Reverse lookup a nested dictionary

Dictionary...> nestedDictionary; Above Dictionary has a one-to-many relationship at each level from top to bottom. Adding an item is pretty easy since we have the leaf object and we start from bottom, creating…
Xaqron
  • 29,931
  • 42
  • 140
  • 205
2
votes
2 answers

How to do a reverse foreignkey lookup for all records in Django?

I'm trying to do a reversed SQL lookup using Django 1.3. I found a lot of related questions, but unfortunately I can only find the answer for doing this on a single record, not on multiple records at once. Basically, this is my case: I have a model…
lunanoko
  • 486
  • 1
  • 7
  • 16
2
votes
3 answers

Django - reverse lookups

For example, I have these models: class Person(models.Model): name = models.CharField(max_length=20) employer = models.CharField(max_length=20) class Car(models.Model): person = models.ForeignKey(Person) name =…
yetty
  • 2,326
  • 2
  • 19
  • 22
2
votes
1 answer

Mapping .svn/pristine file back to file in svn (reverse lookup)

So I found a file inside .svn folder which has filename like this. .svn/pristine/fa/faa0544abc11c14647e18c2ee1283b445a1fa1e1.svn-base Now by looking at contents of this file I want to figure out which filename it had in SVN tree. It has been deleted…
ckain
  • 383
  • 5
  • 13
2
votes
2 answers

Finding the domain name of a site that is hotlinking in Google app engine using web2py

Let's say we have an image in the Google App Engine and sites are hotlinking it. How can I find the domain names of the sites? My first thought was: request.client and then do a reverse lookup but that it's not possible in GAE and would take a lot…
Jon Romero
  • 4,062
  • 6
  • 36
  • 34
1
2 3 4