[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

array manipulation

Analogy Analogy

9/25/2007 2:37:00 PM

Hi Folks,

I have a general newbie type question
Say I have a 2D array that I obtained from an external program:

array = [["a", "b", "", "c", "5"], ["d", "e", "f", "9.0", "7", "g", "",
"", ""], ["", "h", "5", "", ""]]


Is there a way to remove just the last two empty strings ("") in the
last element, so the array will look like this:

array = [["a", "b", "", "c", "5"], ["d", "e", "f", "9.0", "7", "g", "",
"", ""], ["", "h", "5"]]

I've looked at array.compact, but this removes all of the empty
strings(""), plus I'd have to flatten the array to 1D, which is no good.
Thanks in advance!
--
Posted via http://www.ruby-....

10 Answers

SpringFlowers AutumnMoon

9/25/2007 3:05:00 PM

0

Analogy Analogy wrote:
> Hi Folks,
>
> I have a general newbie type question
> Say I have a 2D array that I obtained from an external program:
>
> array = [["a", "b", "", "c", "5"], ["d", "e", "f", "9.0", "7", "g", "",
> "", ""], ["", "h", "5", "", ""]]
>
>
> Is there a way to remove just the last two empty strings ("") in the
> last element, so the array will look like this:
>
> array = [["a", "b", "", "c", "5"], ["d", "e", "f", "9.0", "7", "g", "",
> "", ""], ["", "h", "5"]]

you can use array[2][3,2] = nil to delete the last 2 elements
and use flatten to get a new array

--
Posted via http://www.ruby-....

Robert Dober

9/25/2007 3:13:00 PM

0

On 9/25/07, Analogy Analogy <analogy47@aol.com> wrote:
> Hi Folks,
>
> I have a general newbie type question
> Say I have a 2D array that I obtained from an external program:
>
> array = [["a", "b", "", "c", "5"], ["d", "e", "f", "9.0", "7", "g", "",
> "", ""], ["", "h", "5", "", ""]]
>
>
> Is there a way to remove just the last two empty strings ("") in the
> last element, so the array will look like this:
>
> array = [["a", "b", "", "c", "5"], ["d", "e", "f", "9.0", "7", "g", "",
> "", ""], ["", "h", "5"]]
>
> I've looked at array.compact, but this removes all of the empty
> strings(""), plus I'd have to flatten the array to 1D, which is no good.
> Thanks in advance!
> --
> Posted via http://www.ruby-....
>
>
2.times{ array.last.pop }

but is this really what you want? I mean are you not up to something
more general?
for example:
2.times{ array.last.pop if array.last.empty? }
do you see what I mean?

Cheers
Robert

--
I'm an atheist and that's it. I believe there's nothing we can know
except that we should be kind to each other and do what we can for
other people.
-- Katharine Hepburn

paul

9/25/2007 4:05:00 PM

0

On Tue, 2007-09-25 at 23:36 +0900, Analogy Analogy wrote:
> Hi Folks,
>
> I have a general newbie type question
> Say I have a 2D array that I obtained from an external program:
>
> array = [["a", "b", "", "c", "5"], ["d", "e", "f", "9.0", "7", "g", "",
> "", ""], ["", "h", "5", "", ""]]

this any good?
i'd assumed you just wanted to get rid of the two empty strings as
they're duplicates...

irb(main):015:0> arr = [['paul','fox','',''],['testing','123','','']]
=> [["paul", "fox", "", ""], ["testing", "123", "", ""]]
irb(main):016:0> arr.map{|a| pp a.uniq}
["paul", "fox", ""]
["testing", "123", ""]
=> [nil, nil]
irb(main):017:0>


Winston Smith, American Patriot

5/1/2011 9:36:00 PM

0

rfischer@sonic.net (Ray Fischer) wrote on Sun 01 May 2011 10:59:33p

> Werner <whetzner@mac.com> wrote:
>>On May 1, 8:04?pm, Phlip <phlip2...@gmail.com> wrote:
>>> The High Cost of Low Teacher Salaries
>>> By DAVE EGGERS and N?NIVE CLEMENTS CALEGARI
>>> San Francisco
>>> WHEN we don't get the results we want in our military endeavors, we
>>> don't blame the soldiers. We don't say, "It's these lazy soldiers and
>>> their bloated benefits plans! That's why we haven't done better in
>>> Afghanistan!" No, if the results aren't there, we blame the planners.
>>> We blame the generals, the secretary of defense, the Joint Chiefs of
>>> Staff. No one contemplates blaming the men and women fighting every
>>> day in the trenches for little pay and scant recognition.
>>> And yet in education we do just that. ...
>>
>>When soldiers don't perform in the military they die. When teachers
>>don't perform in public schools they get more money to "reform".
>
> When CEOs fail and nearly destroy their companies, they get fired and
> are given $30,000,000 severace payouts.

Or they manage to engineer bailouts from taxpayers, and not only keep their
jobs, but get high fives in the boardroom.





--
The real danger to the future of humanity is the preference
for surrendering to fear, superstition, and faith
in absolutist belief systems, and so to submit to these
willingly and to the control of those demagogues who
make use of these, rather than preferring
to reason with one's own mind.


http://mavigozler.awards...

Werner

5/2/2011 5:59:00 AM

0

On May 1, 11:36 pm, "Winston Smith, American Patriot"
<FranzKa...@Oceania.WhiteHouse.GOV.invalid> wrote:
> rfisc...@sonic.net (Ray Fischer) wrote on Sun 01 May 2011 10:59:33p
>
>
>
>
>
> > Werner  <whetz...@mac.com> wrote:
> >>On May 1, 8:04 pm, Phlip <phlip2...@gmail.com> wrote:
> >>> The High Cost of Low Teacher Salaries
> >>> By DAVE EGGERS and NÍNIVE CLEMENTS CALEGARI
> >>> San Francisco
> >>> WHEN we don't get the results we want in our military endeavors, we
> >>> don't blame the soldiers. We don't say, "It's these lazy soldiers and
> >>> their bloated benefits plans! That's why we haven't done better in
> >>> Afghanistan!" No, if the results aren't there, we blame the planners.
> >>> We blame the generals, the secretary of defense, the Joint Chiefs of
> >>> Staff. No one contemplates blaming the men and women fighting every
> >>> day in the trenches for little pay and scant recognition.
> >>> And yet in education we do just that. ...
>
> >>When soldiers don't perform in the military they die. When teachers
> >>don't perform in public schools they get more money to "reform".
>
> > When CEOs fail and nearly destroy their companies, they get fired and
> > are given $30,000,000 severace payouts.
>
> Or they manage to engineer bailouts from taxpayers, and not only keep their
> jobs, but get high fives in the boardroom.
>
> --


The desire to shift costs to others is widely practiced. That is why
the culture and country are bankrupt.
http://www.EndIt.inf...



> The real danger to the future of humanity is the preference
> for surrendering to fear, superstition, and faith
> in absolutist belief systems, and so to submit to these
> willingly and to the control of those demagogues who
> make use of these, rather than preferring
> to reason with one's own mind.
>
> http://mavigozler.awards...

Werner

5/2/2011 6:02:00 AM

0

On May 1, 9:59 pm, rfisc...@sonic.net (Ray Fischer) wrote:
> Werner  <whetz...@mac.com> wrote:
> >On May 1, 8:04 pm, Phlip <phlip2...@gmail.com> wrote:
> >> The High Cost of Low Teacher Salaries
> >> By DAVE EGGERS and NÍNIVE CLEMENTS CALEGARI
> >> San Francisco
> >> WHEN we don't get the results we want in our military endeavors, we don't
> >> blame the soldiers. We don't say, "It's these lazy soldiers and their bloated
> >> benefits plans! That's why we haven't done better in Afghanistan!" No, if the
> >> results aren't there, we blame the planners. We blame the generals, the
> >> secretary of defense, the Joint Chiefs of Staff. No one contemplates
> >> blaming the men and women fighting every day in the trenches for little pay
> >> and scant recognition.
> >> And yet in education we do just that. ...
>
> >When soldiers don't perform in the military they die. When teachers
> >don't perform in public schools they get more money to "reform".
>
> When CEOs fail and nearly destroy their companies, they get fired and
> are given $30,000,000 severace payouts.
>
> --


This would not be tax dollars. Privately held dollars are not my
concern.



> Ray Fischer         |  Mendacracy (n.) government by lying
> rfisc...@sonic.net  |  The new GOP ideal

liberal

5/2/2011 8:05:00 PM

0

On May 2, 1:59 am, Werner <whetz...@mac.com> wrote:
> On May 1, 11:36 pm, "Winston Smith, American Patriot"
>
>
>
>
>
> <FranzKa...@Oceania.WhiteHouse.GOV.invalid> wrote:
> > rfisc...@sonic.net (Ray Fischer) wrote on Sun 01 May 2011 10:59:33p
>
> > > Werner  <whetz...@mac.com> wrote:
> > >>On May 1, 8:04 pm, Phlip <phlip2...@gmail.com> wrote:
> > >>> The High Cost of Low Teacher Salaries
> > >>> By DAVE EGGERS and NÍNIVE CLEMENTS CALEGARI
> > >>> San Francisco
> > >>> WHEN we don't get the results we want in our military endeavors, we
> > >>> don't blame the soldiers. We don't say, "It's these lazy soldiers and
> > >>> their bloated benefits plans! That's why we haven't done better in
> > >>> Afghanistan!" No, if the results aren't there, we blame the planners.
> > >>> We blame the generals, the secretary of defense, the Joint Chiefs of
> > >>> Staff. No one contemplates blaming the men and women fighting every
> > >>> day in the trenches for little pay and scant recognition.
> > >>> And yet in education we do just that. ...
>
> > >>When soldiers don't perform in the military they die. When teachers
> > >>don't perform in public schools they get more money to "reform".
>
> > > When CEOs fail and nearly destroy their companies, they get fired and
> > > are given $30,000,000 severace payouts.
>
> > Or they manage to engineer bailouts from taxpayers, and not only keep their
> > jobs, but get high fives in the boardroom.
>
> > --
>
> The desire to shift costs to others is widely practiced. That is why
> the culture and country are bankrupt.http://www.EndIt.inf...

And you are part of the fifth columnists who are shifting costs to
others.


>
> > The real danger to the future of humanity is the preference
> > for surrendering to fear, superstition, and faith
> > in absolutist belief systems, and so to submit to these
> > willingly and to the control of those demagogues who
> > make use of these, rather than preferring
> > to reason with one's own mind.
>
> >http://mavigozler.awards...

rfischer

5/3/2011 5:42:00 AM

0

Werner <whetzner@mac.com> wrote:
>On May 1, 9:59?pm, rfisc...@sonic.net (Ray Fischer) wrote:
>> Werner ?<whetz...@mac.com> wrote:
>> >On May 1, 8:04?pm, Phlip <phlip2...@gmail.com> wrote:
>> >> The High Cost of Low Teacher Salaries
>> >> By DAVE EGGERS and N?NIVE CLEMENTS CALEGARI
>> >> San Francisco
>> >> WHEN we don't get the results we want in our military endeavors, we don't
>> >> blame the soldiers. We don't say, "It's these lazy soldiers and their bloated
>> >> benefits plans! That's why we haven't done better in Afghanistan!" No, if the
>> >> results aren't there, we blame the planners. We blame the generals, the
>> >> secretary of defense, the Joint Chiefs of Staff. No one contemplates
>> >> blaming the men and women fighting every day in the trenches for little pay
>> >> and scant recognition.
>> >> And yet in education we do just that. ...
>>
>> >When soldiers don't perform in the military they die. When teachers
>> >don't perform in public schools they get more money to "reform".
>>
>> When CEOs fail and nearly destroy their companies, they get fired and
>> are given $30,000,000 severace payouts.
>
>This would not be tax dollars.

So what?

> Privately held dollars are not my
>concern.

Don't you dumbass rightards keep whining that higher business taxes
means higher prices?

--
Ray Fischer | Mendacracy (n.) government by lying
rfischer@sonic.net | The new GOP ideal

Werner

5/3/2011 8:39:00 AM

0


You dumbass Leftards wonder why jobs are lost. That would be because
customers prefer to pay less. And taxes increase prices.

trainguard

5/3/2011 9:26:00 AM

0

On May 1, 8:05 pm, Werner <whetz...@mac.com> wrote:
> On May 1, 8:04 pm, Phlip <phlip2...@gmail.com> wrote:
>
> > The High Cost of Low Teacher Salaries
> > By DAVE EGGERS and NÍNIVE CLEMENTS CALEGARI
> > San Francisco
> > WHEN we don't get the results we want in our military endeavors, we don't
> > blame the soldiers. We don't say, "It's these lazy soldiers and their bloated
> > benefits plans! That's why we haven't done better in Afghanistan!" No, if the
> > results aren't there, we blame the planners. We blame the generals, the
> > secretary of defense, the Joint Chiefs of Staff. No one contemplates
> > blaming the men and women fighting every day in the trenches for little pay
> > and scant recognition.
> > And yet in education we do just that. ...
>
> When soldiers don't perform in the military they die.

Not always. Some get promoted. Teachers do die sometimes..from ill
health and stress-related medical conditions. But, as the article
states, many don't get that far...they leave.

I have worked in education for over thirty years. Things aren't nearly
so bad in Britain as they are in America. But believe me, the piece
really hit the nail on the head!



>When teachers
> don't perform in public schools they get more money to "reform".

Teacher's don't. The largely Federal financed schemes seem to be in
the hands of local administrators, and are directed at ways of
tinkering with problems. They are not fundamental 'root and branch'
reforms. For that, you appear to need better School Boards, with
members that are not ideological freaks or religious nutters, and a
local population prepared to pay more to invest in the future of their
kids...

> ....
>  If we're committed to "winning the
>
> > future," we should. If any administration is capable of tackling this, it's
> > the current one. President Obama and Education Secretary Arne Duncan
> > understand the centrality of teachers and have said that improving our
> > education system begins and ends with great teachers. But world-class
> > education costs money.
>
> This is the usual refrain. Hasn't worked for decades.

What hasn't worked? Nobody has fundamentally reformed your teaching
system in decades. (I leave aside ideological and agenda driven ideas
like vouchers that are clearly insane.

> On the other hand, if "we the people'' must pay for a "money pit''

What money pit? Your problem, Werner (apart from the fact that you
believe in all that 'libertarian' and 'free market' nonsense) is that
you don't inhabit the real world...as the rest of us do...

>  we
> obviously don't want, does that not make us accountable to
> government?http://capitaldistrict-lp.org/Accountable.shtmlhttp://capitaldistrict-lp.org/Education.shtmlhttp://capitaldistrict-lp.org/PerformanceGap.shtmlhttp://capitaldistrict-lp.org/ReportCard.shtmlhttp://capitaldistrict-lp.org/Sch...
> despite the fact that the U.S. spends the largest amount of money per
> pupil in the world,

Actually, it doesn't. You can't quote national figures, since there is
no continuum in spending between States and localities within States.

>standardized international achievement tests
> reveal that U.S. public schools achieve mediocre scores.. For
> example,
> according to the 2000 Program for International Student Assessment
> (PISA) for 15-
> year-old students, the U.S. ranked 15th in reading, 18th in
> mathematics, and 14th in science literacy among 27 OECD countries
> (U.S. DOE, 2001).http://www.uwm.edu/~kim/papers/Accountability...
>

And national figures are distorted by a variety of (usually) regional
and local factors.

It also reflects upon the way that your system is structured....and
measured...

But as you seem to know nothing about education, Werner, such
consideration might not occur to you...

> > For those who say, "How do we pay for this?" -- well, how are we paying for
> > three concurrent wars? How did we pay for the interstate highway system? Or
> > the bailout of the savings and loans in 1989 and that of the investment
> > banks in 2008? How did we pay for the equally ambitious project of sending
> > Americans to the moon? We had the vision and we had the will and we found a
> > way.
>
> Vision is not enough. We have been throwing money at public education
> for decades, much as we have with other visions promised by Bigger
> and
> Bigger BigGovernment.

But...education is primarily a local School Board and State
responsibilty! I know that, and I'm not an American!



>All "we" have to show for it is national
> bankruptcy and a culture of dependence presided over by an expanding
> police state.

It would help if you actually bothered to find out what was going on.
You can't be content to spew ideologal mantras all your life.

By the way, what was your educational experience? I would be
interested.

Dr. Barry Worthington