Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #94409
| Return-Path | <python-python-list@m.gmane.org> |
|---|---|
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.007 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'csv': 0.09; 'dict': 0.09; 'ignoring': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'assume': 0.11; 'combinations': 0.16; 'dict(': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:array': 0.16; 'wrote:': 0.16; 'transform': 0.18; 'arrays': 0.22; 'file.': 0.22; 'code,': 0.23; 'code.': 0.23; 'this:': 0.23; 'header:In-Reply- To:1': 0.24; 'header:User-Agent:1': 0.26; 'example': 0.26; 'header:X-Complaints-To:1': 0.26; 'entries': 0.27; 'skip:( 20': 0.28; 'looks': 0.29; 'origin': 0.29; 'array': 0.29; 'convert': 0.29; 'print': 0.30; 'point': 0.33; 'file': 0.34; 'list': 0.34; 'skip:- 50': 0.35; 'filter': 0.35; 'robert': 0.35; 'to:addr :python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'minimum': 0.38; 'represent': 0.38; 'data': 0.39; 'to:addr:python.org': 0.40; 'charset:windows-1252': 0.62; 'office': 0.62; 'distance': 0.63; 'between': 0.65; 'results': 0.66; 'received:12': 0.81; 'miles.': 0.84; 'jersey': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Emile van Sebille <emile@fenx.com> |
| Subject | Re: Find Minimum for element in multiple dimensional array |
| Date | Wed, 22 Jul 2015 16:26:58 -0700 |
| References | <a7fe6fd3-2a51-40a9-b995-33fc88cb27ee@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | www.westernstatesglass.com |
| User-Agent | Mozilla/5.0 (Windows NT 6.2; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 |
| In-Reply-To | <a7fe6fd3-2a51-40a9-b995-33fc88cb27ee@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.891.1437607638.3674.python-list@python.org> (permalink) |
| Lines | 46 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1437607638 news.xs4all.nl 2834 [2001:888:2000:d::a6]:57388 |
| X-Complaints-To | abuse@xs4all.nl |
| X-Received-Bytes | 4811 |
| X-Received-Body-CRC | 1349265336 |
| Path | csiph.com!usenet.pasdenom.info!news.stben.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!bcyclone01.am1.xlned.com!bcyclone01.am1.xlned.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
| Xref | csiph.com comp.lang.python:94409 |
Show key headers only | View raw
On 7/22/2015 3:54 PM, Robert Davis wrote:
> I have an array of arrays that have a origin zip code, origin latitude, origin longitude, destination zip code, destination latitude, destination longitude, and miles between the two points.
>
> I need to keep only those combinations that represent the minimum mileage between to the destination zip code. For example a point in New Jersey may have a distance from the Philadelphia Office that is 45 miles, from the Newark Office that is 78 miles and one from the Delaware Office that is 58 miles.
>
> I need to keep the mileage from the Philadelphia Office that is 45 miles and produce a .csv file that has origin zip code, origin latitude, origin longitude, destination zip code, destination latitude, destination longitude, and miles between the two points.
>
> The array looks like this:
>
> [['37015', 'TN31', 36.2777, -87.0046, 'NY', 'White Plains', '10629', 41.119008, -73.732996, 77.338920003],
> ['72202', 'ARB1', 34.739224, -92.27765, 'NY', 'White Plains', '10629', 41.119008, -73.732996, 1099.7837975322097]]
Assume the array in A:
---8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---
A= [['37015', 'TN31', 36.2777, -87.0046, 'NY', 'White Plains', '10629',
41.119008, -73.732996, 77.338920003],
['72202', 'ARB1', 34.739224, -92.27765, 'NY', 'White Plains', '10629',
41.119008, -73.732996, 1099.7837975322097]]
# transform to a dict ignoring dups
D = dict( [ ( ((r[6],r[0]),r[-1]), r) for r in A ] )
# convert to a sorted list
L = sorted(D.items())
# then print and filter out any duplicated entries
lastzippair = (None,None)
for ky,rec in L:
if ky[:2] == lastzippair:
continue
print ky,":",rec
lastzippair=ky[:2]
---8<---8<---8<---8<---8<---8<---8<---8<---8<---8<---
The results are what you'd write to the csv file.
Tested only with the data you provided.
HTH,
Emile
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Find Minimum for element in multiple dimensional array Robert Davis <rdavis7408@gmail.com> - 2015-07-22 15:54 -0700 Re: Find Minimum for element in multiple dimensional array Emile van Sebille <emile@fenx.com> - 2015-07-22 16:26 -0700 Re: Find Minimum for element in multiple dimensional array Robert Davis <rdavis7408@gmail.com> - 2015-07-23 05:31 -0700 Re: Find Minimum for element in multiple dimensional array Robert Davis <rdavis7408@gmail.com> - 2015-07-23 14:50 -0700 Re: Find Minimum for element in multiple dimensional array Denis McMahon <denismfmcmahon@gmail.com> - 2015-07-24 00:18 +0000 Re: Find Minimum for element in multiple dimensional array Robert Davis <rdavis7408@gmail.com> - 2015-07-24 06:17 -0700
csiph-web