473,795 Members | 2,391 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CONTEST - What is the (best) solution?

In a file there can be several dictionaries like this
{Key11: Value11
Key12: Value12
Key13: Value13,
....
....
Key1n:Value1n}
{Key21: Value21
Key22: Value22
Key23: Value23,
....
....
Key2n:Value2n}
{Key31: Value31
Key32: Value32
Key33: Value33,
....
....
Key3n:Value3n}
.....
.....
.....
{Keyn1: Valuen1
Keyn2: Valuen2
Keyn3: Value3,
....
....
Keynn:Valuenn}

Each pair in a dictionary is separated by CRLF and in each dictionary
numbers of pairs can be different.
I need to read only the the first and the last dictionaries.Wh at is a
best solution?
Thanks
Lad

Jul 18 '05
12 1612
Cappy2112 wrote:
dictionaries can NOT contain dictionaries.


Who told you this?
In my python, they can.
[snip]


You took his reply out of context. Fuzzyman asked him if *his*
dictionaries were to contain dictionaries, and the reply was no, they
will not.

--
Daniel Bickett
dbickett at gmail.com
http://heureusement.org/
Jul 18 '05 #11
Hello Lad,
In a file there can be several dictionaries like this
{Key11: Value11
Key12: Value12
Key13: Value13,
...
...
Key1n:Value1n}
{Key21: Value21
Key22: Value22
Key23: Value23,
...
...
Key2n:Value2n}
{Key31: Value31
Key32: Value32
Key33: Value33,
...
...
Key3n:Value3n}
....
....
....
{Keyn1: Valuen1
Keyn2: Valuen2
Keyn3: Value3,
...
...
Keynn:Valuenn}

Each pair in a dictionary is separated by CRLF and in each dictionary
numbers of pairs can be different.
I need to read only the the first and the last dictionaries.Wh at is a
best solution?


---- d.py ---

#!/usr/bin/env python

from sys import argv

dicts = eval("[" + open(argv[1]).read().replac e("}", "},") + "]")
print dicts[0], dicts[-1]

---- d.py ---

HTH.
--
------------------------------------------------------------------------
Miki Tebeka <mi*********@zo ran.com>
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys

Jul 18 '05 #12
> {Key11: Value11
....
{Keyn1: Valuen1
Keyn2: Valuen2
...
Keynn:Valuenn}

Each pair in a dictionary is separated by CRLF and in each dictionary
numbers of pairs can be different.
I need to read only the last dictionary.What is a
best solution?
Thanks
Lad


What about (not tested):

stmFile = file(r"Path\Fil eNameOfTheFileW ithDictionaries ")
strFile = stmFile.read()
strLastDict = strFile[strFile.rfind(' \n{"):]

?

Claudio


Jul 18 '05 #13

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

Similar topics

3
2271
by: Matt Wade | last post by:
A new PHP Coding Contest has been released at Codewalkers.com. The latest challenge is to play a variation of the Numbers Game as seen on the UK television show Countdown. Basically, you are supplied with 6 numbers and a target number. Your program should manipulate the 6 numbers with basic arithmetic operators to reach the target number. More information can be had at: http://codewalkers.com/php-contest.php
1
2167
by: vpd | last post by:
hi, I want some help in organising an online programming contest. Is there a ready made solution available in PHP or even Perl which I could use? The contest is supposed to be based on C programming and the solutions submitted by the participants must be compiled, executed and the marks shall be allocated automatically. I want some urgent help as the contest is supposed to be organised in just a couple of days. Any suggestions and...
0
1281
by: Robby Findler | last post by:
Think your favorite programming language is the best one out there? Put it to the test in this year's International Conference on Functional Programming's annual Programming Contest. The contest is coming up in a little under 4 weeks and we have just released more information (including a live cd, mailing list, and prize details) to the web page, at: http://icfpc.plt-scheme.org/ This year's competition rewards programmers who can plan...
16
1619
by: hicinbothem | last post by:
GLOSSY: The Summer Programmer Of The Month Contest is underway! Deadline is September 30, 2005 http://dinsights.com/POTM -------------------------------------------------------------------------------- I love taking digital pictures, but that nice glossy photo paper is expensive! So when my lovely wife asks for prints of a bunch of pictures, I always try and fit them onto a single piece of paper. The summer POTM challenges you to...
13
2280
by: Brian Quinlan | last post by:
I've decided that it would be be fun to host a weekly Python programming contest. The focus will be on algorithms that require a bit of thought to design but not much code to implement. I'm doing to judge the solutions based on execution speed. It sucks but that is the easiest important consideration to objectively measure. I'll also indicated which solutions I think are good examples of Python design. Hopefully, people's solutions can...
87
5263
by: ziliath | last post by:
I recently tried out the Google "top coder" contest, as a C++ coder. I noticed immediately that they expected me to know STL. To which I say, what the fuck?! I may be missing something, but at what point when learning C++ was I supposed to have picked up STL? I ask because at every job I've had, and every job interview for that matter, whenever STL comes up it's not I, but a manager who says effectively yuck, we don't use that crap.
1
1470
by: Catherine Chronaki | last post by:
The OpenECG programming contest is now open to submissions. Prizes total 10,000 Euros. For more information, visit the OpenECG portal: http://www.openecg.net and click on Programming Contest. Questions may be addressed to contest@openecg.net.
19
2378
by: virtualadepts | last post by:
This contest is open to everyone who knows C++. To enter all you need to do is take the Boyer-Moore String Search Algorithm, as it is written in C, and make the fastest running C++ program you can out of it. I'm going to try to write code myself, and if you can beet me, and your code executes faster, then you win a free I-Pod. My I-Pod is used, but it comes jam packed with songs I've been listening to. So take a crack at this problem...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10438
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.