Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #68577
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news2.arglkargh.de!diablo1.news.osn.de!news.osn.de!diablo2.news.osn.de!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ishish@domhain.de> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.013 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'else:': 0.03; 'f.close()': 0.09; 'newline': 0.09; 'trees': 0.09; 'python': 0.11; 'creates': 0.14; '(k,': 0.16; 'dict': 0.16; 'dictionaries': 0.16; 'script?': 0.16; 'obviously': 0.18; 'trying': 0.19; 'split': 0.19; 'print': 0.22; 'header:User-Agent:1': 0.23; 'script': 0.25; 'asking': 0.27; 'header:In-Reply-To:1': 0.27; 'fine,': 0.31; 'file': 0.32; "can't": 0.35; 'but': 0.35; 'there': 0.35; 'hi,': 0.36; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'new': 0.61; 'numbers': 0.61; 'different': 0.65; 'phone': 0.66; 'sound': 0.68; 'limit': 0.70; 'ref': 0.84 |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Date | Thu, 20 Mar 2014 13:11:44 +0000 |
| From | ishish <ishish@domhain.de> |
| To | <python-list@python.org> |
| Subject | Dictionaries |
| In-Reply-To | <CANXBEFogXsze6WByg_iCit-oLEQK-RXsgJCDM=ocZ7JPNgdb8g@mail.gmail.com> |
| References | <CANXBEFogXsze6WByg_iCit-oLEQK-RXsgJCDM=ocZ7JPNgdb8g@mail.gmail.com> |
| X-Sender | ishish@domhain.de |
| User-Agent | RoundCube Webmail/0.7.1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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.8300.1395322251.18130.python-list@python.org> (permalink) |
| Lines | 51 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1395322251 news.xs4all.nl 2856 [2001:888:2000:d::a6]:50579 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:68577 |
Show key headers only | View raw
Hi,
This might sound weird, but is there a limit how many dictionaries a
can create/use in a single script?
My reason for asking is I split a 2-column-csv (phone#, ref#) file into
a dict and am trying to put duplicated phone numbers with different ref
numbers into new dictionaries. The script deducts the duplicated 46
numbers but it only creates batch1.csv. Since I obviously can't see the
wood for the trees here, can someone pls punch me into the right
direction....
...(No has_key is fine, its python 2.7)
f = open("file.csv", 'r')
myDict = {}
Batch1 = {}
Batch2 = {}
Batch3 = {}
for line in f:
if line.startswith('Number' ):
print "First line ignored..."
else:
k, v = line.split(',')
myDict[k] = v
f.close()
for k, v in myDict.items():
if Batch1.has_key(k):
if k in Batch2.has_key(k):
Batch3[k] = v
else:
Batch2[k] = v
else:
Batch1[k] = v
for k, v in Batch1.items():
newLine = "%s,%s" % (k, v)
with open("batch1.csv", "a") as f:
f.write(newLine)
for k, v in Batch2.items():
newLine = "%s,%s" % (k, v)
with open("batch2.csv", "a") as f:
f.write(newLine)
for k, v in Batch3.items():
newLine = "%s,%s" % (k, v)
with open("batch3.csv", "a") as f:
f.write(newLine)
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Dictionaries ishish <ishish@domhain.de> - 2014-03-20 13:11 +0000 Re: Dictionaries John Gordon <gordon@panix.com> - 2014-03-20 14:19 +0000
csiph-web