Search This Blog

Sunday, April 19, 2020

...text for Apr. 19, 2020

I, Jehovah, am ... teaching you to benefit yourself. - Isa. 48:17
 The comments on this text today focused on parents endeavoring to raise their children to be good people. But the superlative Parent of all is our heavenly Father. The impact of this verse is this: Jehovah ALWAYS does things for the benefit of others. Is there any other Being like Him, that he could turn to and say, "Look! I created earth and man. See?" No.

We exist simply because He decided to create. If He chose not to create anything, we wouldn't exist. Every decision he makes is well within his right, because of his status as the Creator, the Almighty God Jehovah. So, He desn't receive anything of his creation, except the satisfaction that he created it. He is greatly satisfied when we puny humans, the "specks of dust", do our best to please Him. And, so he teaches us, disciplines us (sometimes painfully), so that we can live in a way that makes him happy, and it's to OUR benefit that HE does so.

Now, think about your mother and father. If they had decided not to have children, you would not have been born. Yet, they created YOU. It doesn't matter if it was an accident ("Oos, the condom broke) or it was a planned deal, they still created you. They want you to benefit yourselves, so they try, even as imperfect people, to train you, disciplin you (sometimes painfully), to do well, and to live as reasonable human beings. The Almighty  Father laid the responsibilty on the human father to follow His example, so that YOU can benefit. The parents get satisfaction that they did well, just as Jehovah receives satisfation that He did well. So, instead of grumbling about the early curfew, or the mundane and boring tasks they give you, think about how it goes up the shain, through your father to his Father in heaven, and that's a good thing.

Even if your parents don't serve Jehovah, they still have the right and responsibility given to them by God. There is no loophole.

Because Jehovah gave so much of himself, as his son, Jesus also did, it's in our best interests to pay attention to what the Bible says and to follow his Commandments. As we show appreciation for what Jehovah didn't have to do (create, provide a ransom, or give us His Word, the Bible), we need to meditate soberly on this text and examine ourselves to determine our motives, and ask ourselves: Do I seek my own benefit at others' expense? Do I treat myself better than I treat others? Do I have the proper fear of Jehovah, who sees what I do in private? Do we meditate on Psalm 92:5 and do what we can to search and meditate on Jehovah's works and his sayings in an attempt to imitate Him?

If you continue to check yourself in this way, then everything you do will be successful.

Stay safe.

Saturday, April 18, 2020

The Art of Dining Alone

    "It's my birthday." He told the weather-worn waitress with blond hair and a name tag that read "Darleen". He didn't know if it was a typo or really her name.
    She brightened up slightly.
    "Oh! Wonderful news! How old are you today, birthday boy?"
    "Ancient," he replied, ashamed at blurting that out. Was he hoping for a free meal? Was he being flirty? He wasn't quite sure. "Look, please don't sing that song or bring me a cake with one little candle. I don't celbrate birthdays." He didn't feel like explaining it, so he left it at that. He looked at the over sized menu that had more pages than a Tom Clancy novel.
    She held her pad in her left hand, her pencil hovering like a helicopter, ready to drop and write concentric orders in a crazy doodle for the cook to decipher.
    "Um, would you like something to drink?" The smile dimming just a bit.
    "Coffee, I'd appreciate that." He said charmingly, so make her feel a little better.
    "We do give a free meal for a birth...."
    "Oh no, that's fine. I was planning on a big breakfast anyhow," he cut her off.
    The letters on the menu were distorted. The black letters shifting their vertical lines. He slightly cocked his head until they lined up a little better. He looked for a meal that he hadn't tried yet, even though he often went to this diner.
    He really loved this restaurant, eating there frequently. Usually he saw the same workers, but he didn't recognize his waitress. Must be new.
    The menu had the usual assortment of breakfast items and burgers and salads for lunch. His favorite menu item was the "loaded hash browns". He took every opportunity to order it with his meal. Even at dinner-time. He remembered once telling the bewildered server, a slight, frail-looking brunette, maybe 25, that he would have the "Mediterranean chicken with rice pilaf and dinner bread, with a plate of loaded hash browns on the side."
    What were the "loaded hash browns"? He imagined telling his virtual son that they were a lovely concoction, hash browns stuffed with sour cream with onions, bell peppers and cheese smothered on top, as if it was a loaded baked potato. Heaven!
    Not finding anything unique on the menu, as it was breakfast time anyway, he ordered, his usual, the "Meat Lover's Special" (bacon, sausage and ham!) with the loaded hash browns, with a small apple juice and his coffee.
    Darleen wrote dutifully on her pad, promised the coffee, took the huge menu and sashayed away, trailing s hint of Coco Chanel #5 in her wake.
    He looked around the busy restaurant. The other patrons were blurry and had different shapes and colors. Three tables away, a baby gurgled in his high chair, and pounded the little attached table like he was calling his court to order.
    His mother, held up some eggs on a spoon and held it toward her child. He sniffed, then opened his mouth for  "yiddle plan to land in the hangar" as mother cooed encouragement.
    He turned away and noticed his steaming coffee sitting there. He didn't see Darleen bring it. He drank it black, so he raised it to his lips to test the temperature. It was slightly scalding. He decided to wait. He looked out the window and the vehicular blobs flying past, thundering down the freeway (so close!) and going off to who knows where. He turned back to see his apple juice had magically appeared also. He looked around to see if he could spot Darleen aka Houdini, but she was nowhere in sight. He took a sip of the cool, sweet liquid and thought about his glucose level.
    He fumbled in his jacket pocket and pulled out his glucose meter, with the insulin pen zipped into it, its top sticking out like a flag. Unzipping it open, he felt for the capped needle and found it. Peeling off the sanitation cover, he screwed it on and rotated the dial on the end, counting the clicks to the desired dosage. He couldn't see the number, but figured it was right. He uncapped the needle, took off the second protector on the needle itself, lifted up his shirt and discreetly, under the table, administered his dose.
    Twenty years of diabetes and he still hated it. For a long time, he didn't care about it, just ate whatever he wanted, taking a pill twice a day to control it. But, that hadn't helped. Now, he was really focused on making sure he had enough medication, so he would take what he thought he needed for the meal and test it later to see if his deductions where correct. Sometimes, he over-estimated and his brain would feel woozy and dizzy for low blood sugar and he would take a chew able sugar tablet to bring it up closer to normal. Other times, he would under-guess and his feet would feel more numb than usual. But, he did his best, but twenty years older, and today, feeling fatigued, a little sorry for himself, wanting to throw up his hands and say, "All right! All right! Enough!"
    The food came. The three meats all huddled in one corner of the plate, as if they were trying to avoid danger overhead. Did it look like the bacon was protecting the sausage, or was the big slab of ham supporting them both? He speared the sausage and tasted it/ Pork links with the skin on, not those nasty turkey things. Yummy! The bacon, well, wasn't as crispy as he liked, more fatty and soft.
    The eggs were fluffy and he poured some Tabasco on them for some flavor. The hash browns would be last, the best part of the meal, and worth the wait. Darleen flashed by and slid a small plate with toast in his general direction.
    "More coffee?" She purred. He nodded, mouth full as she poured more into the mug. "Anytime you're ready," she counseled, laying the ticket face down on the country. Why did they do that? If they put it face up, what would happen? "Ye gods! Four dollars for a coffee?? Manager!" He flipped it to see how much. Yes, pricey but those were great hash browns.
    The meal over, dawdling over a third helping of coffee, he decided it was time to go. He stood painfully, stretching his bent legs and cracking his neck. One hand pulled out his wallet, the other grabbing his hat and cane. All geared up, he took the bill to the front and paid. A jolting ride home to quiet and an audio book, currently a collection of James Thurber short stories.
    He calculated how long to his next fix of loaded hash browns, which wasn't long, and looked forward to another chance at eating out.

...text for April 18, 2020

Jehovah  God planted in Eden...and there he put the man whom he had created. - Gen. 2:8
This is a beautiful text to meditate on. We've seen beautiful parks ourselves in our day. The stately Central Park of New York, or the splendor of Yosemite or Yellowstone.

But, when you read this account in Genesis, do you imagine the Eden being small? I did. The text comments today made me realize that Eden was much larger. It abounded with "every tree" (Gen. 1:29). In this same verse, Adam had every seed to grow things.  For example, there are 2.500 varieties of apples in the world today. Think of it: If you had 2,500 apple trees, eating a different apple per day, it would take almost 7 years before you got back to the first apple you ate! Now, think about the hundreds to thousands of varieties of other fruits and vegetables. The grden of Eden had to be of suffieient size to hold all these and the animals also!

Jehovah wasn't content to leave it a one thing of a kind, but abundantly supplied so many things to Adam and Eve.  They literally had *everything*, but threw it away because Satan "offered" something  a little bit more, that was really unreachable (as if everything was not enough!).

That's like being on some game show, and you're given the choice of a huge prize, like a new house, and you bet it on whatever was behind Door #2, only to find that the prize behind that door was a 20%-off coupon for a steak dinner at your local Black Angus! What lunacy! And you can't revoke your choice and say you'd like the house. It's done, no do-over!

But, to imagine Eden as a really huge and beautiful park, bigger than Yosemite, and to see yourself living it it, that's what you need to visualize for yourself. The reality will even surpass what we can imagine using our imperfect brains. You may decide you want to live at the beach, or live in the mountains, but whee ever it is, it will be breath-taking awesome.

So, among the panic of COVID-19, close your eyes and tell yourself that the future holds amazing beauty and there's plenty for everyone.

Stay safe!

Friday, April 17, 2020

...the text for, Apr. 17, 2020

If the unbelieving one chooses to depart, let him depart. - 1 Cor. 7:15
Thinking bout today's text, I wad thinking of just how beneficial it is to know and serve Jehovah. In fact, this spreads to the rest of the family.

Even though the admonition said to let "him" (or her) go, it's not a response of a shrug and "Oh, well, do what you wanna do". That's not what it says. If the unbeliever says to himself/herself, "Man, my mate is not doing the bad things we used to enjoy doing, this really cramps my style. I'm outta here." Okay, they have the right to make that choice. They should let the door hit them on the way out.

But, even worldly wedding vows say "for better and worse, through thick and thin", the counsel is to stick together and make your best effort at it. If the unbeliever thinks his/her life is much better than before, it's a good thing. In fact, Paul did say in the previous verse (vs 14)  that the "unbelieving husband or wife is sanctified in relation to the brother/sister". Think of that. The unbelieving one has a shot at everlasting life, by virtue of his mate. And it includes any children.

What if it's a case of both mates in the truth, yet one is spiritually stronger than the other? Again, this applies because the weaker one will sometimes make choices that are wrong. If he or she chose to leave, okay, that's their choice, but they both should have the view of reconciling and getting together again. In all case, we should try to make a marriage work. If it fails, and the other firmly decides to go, you can be assured you tried and stick to Jehovah tightly and He will bless you accordingly.

Thursday, April 16, 2020

The Store - A little fiction?

    He hated going to the store. The weekly ritual, previously a joyful excursion, was now a ball of stress and pressure.
    This pandemic was getting out of hand. The stay-at-home order was a irritation. But, he told himself, a man's gotta do what a man's gotta do.
    He lived in a little apartment, in a small suburb north of a metropolis. He didn't require much for his needs. But, today, he needed eggs and milk.
    Squinting into the fridge, he couldn't see the labels on the things he bought. He was slowly going blind, the effects of diabetes, that caused bleeding in his eyes and destroyed his vision. But, he managed to cook for himself, and maybe some people would laugh at the simple fare he made for himself.
    He enjoyed cooking. It was a routine that he kept to avoid gng out to eat processed food from a fast-good place. Yes, he cooked a lot of pasta. It was easy enough to hear the water boiling and telling his phone to set a timer for the allotted minutes. He only cooked sausage and bacon and sometimes, a luxury, ground beef. He could tell when they were ready to eat, the smoke alarm sometimes told him so.
    But, today, he needed eggs, and milk. Was he out of toilet paper? He looked and decided he needed more rolls. Cpffee, he noted, as he looked through his cupboards, was getting low. Add that to the small list he created in his head.
    So began the ritual of getting dressed. After showering, he dressed in a snap-button shirt, jeans with a belt and his orthopedic shoes. He surveyed himself, looking for any spots on his clothes, at least the ones that contrasted with the dark blue of his pants, or the plaid black-and-gray of his shirt. It looked okay to him. Satisfied that he was fully dressed, he got his electric razor and shaved his stubble. Then he felt his hair and it was nearly an afro. He put some gel on that and got the hair flat and neat. Squirting the toothpaste directly in his mouth, he brushe his teeth and contemplated the blurry reflection in the mirror. He couldn't see his facial expression. He made several faces, a frown, a d smile, a surprised face, all indistinguishable.
    Now, he was ready. He picked up his phone, grabbed his magnifying glass, and opened his bus application. He made out that he had 20 minutes to get to the bus stop, so he decided to go ahead and go. Walking there was a dangerous journey and he didn't mind waiting once he got there.
   He got his mandatory mask, his plastic gloves, his hat, sunglasses and cane. He put a jacket on, as Siri chimed that today was "52 degrees". He put his wallet and keys in the customary pockets and left.
   He had lived in this building for a number of years and had memorized the number of steps and how far he had to go. He walked past the pool, barely missing the "We Floor" placard, that was bright yellow and, to him, nearly blended with the ground. He slowly descended the stairs, counting them silently to ensure he didn't miss one and fall to his untimely death (or brain damage, hel hoped) and out the main gate.
   As he stood there and breathed in the slight breeze, he could see different colored blobs, whizzing past him with roars and rumbles and other mechanical noises. He used to be able to identify the make and model of most vehicles, but he only saw them as a car, a truck, a bus or an eighteen-wheeler. He unfastened the strap on his cane and shook it. It clattered out to its full length and he turned left and began his trip to the corner.
   As he approached the fast-food restaurant, he slowed as he reached the driveway. He waited a moment, peering around to see if any blocky shapes were approached to enter or exit the parking lot. Seeing nothing moving, he continued.
   When he got to the corner safely, he felt for the button to call the "Walk" signal and waited. He could barely see hte red light across the street. It flickered in and out of his vision and he kept s;hifting his eyes, not directly looking at it but keeping it visible.
   It turned green, telling him he could go. He looked to see if any cars were turning left, and raised and lowered his cane as he was trained to do, to let others know he was walking. When he stepped into the crosswalk, a little car buzzed into the intersection and turned left in front of him, missing him by a couple of feet. He felt like stoping and waving his arms angrily and expressing anger, but he didn't have time. He could just see the "Don't Walk" blinking, so he hurried, waving his cane again at any would-be jackrabbits with leaded feet and NASCAR on the brain.
   He made it. Breathing deeply, he sat on the bench wo wait. A woman came to wait at the stop too. From several feet away, she asked him which bus he was waiting for. The roar of the traffic drowned her words, and he didn't respond. She gave up, not moving any closer. A man sat on a short brick fence behind them. He could hear this man, who blew his nose repeatedly. It sounded like a dog howling and he looked around for the apparently distressed puppy. Seeing none, he finally saw the man and realized that he was making all that noise. Then he remembered his mask. It was a paper thing, but he strapped it over his ears. His breathing fogged up his sunglasses. He was glad he brushed his teeth, and idly felt his pockets to see if he had any extra mints stowed away.
   The bus came at last, a big, bright, orange box that floated up to the stop. Opening its doors, its recording conversationally stated where it was going. He squinted at the bus number and saw it was the right one. He had his pass ready. He waved it on the transponder and listened for the chirp. The driver asked, "Where do you need to get off?" He named his stop. "Okay, sir, there's a seat to your right." Thanking him, he slowly made his way to his seat and sat down. He adjusted his hat, folded his cane and stared at nothing.
   A man with a Spanish accent was talking loudly on the phone. The one-sided conversation didn't really make sense, possible muffled by his mask, but it went somethig like this: "You kidding? I haven't played that in years. What game you talking about? Zenga, Zynga, Jenga? I don't know no Jenga. Never heard of it. That long? Wow, I wouldna known thaaaat"
   He wondered what it would be like to have a break-up discussion with your girlfriend on the bus without feeling awkward and exposed.
   The bus trundled along, dropping off and picking up people. At one stop, a young boy got on. The driver said, "You're not wearing a mask, the law says you gotta have a mask." The boy protested, but the driver sternly told him to get off the bus. The kid ignored him and walked down the aisle. A big guy stood up and told him hotly that he didn't want this kid to get him sick, so told him to get off. The boy, thinking this was a wise choice, left the bus. Everyone sighed.
   This pandemic.....he thought. He appreciated that where he lived wasn't a complete lock-down, like Italy or other countries. But, it was easy to see everyone was nervous. He focused on the stops being called and breathedd calmly. He finally go off at his stop, and walked to the supermarket where he shopped.
   Entering the store, he could hear some woman screaming that "girls just wanna have funnnnn". Did he need a cart? No. He had a bag in his jacket pocket, but recalled that they banned reusable bags a few days ago. Hg grabbled the plastic basket by the foor and started down the aisles. He had memorized this store as well.
   The coffee aisle was in the middle, so he sarted odwn it. Big bags of coffee were on a shelf shoulder-high. He used the Magnifier app on his phone and zoomed on the coffee brands. He wanted any coffee flavor except Nicaragua. That coffee tasted like old cigarette butts. He debated between Tanzania or Peruvian, and settled on Tanzania. He didn't remember having that yet.
    There were several people in the store. He had arrived after the hour the market set aside for seniors and disabled people, but that was fine. The place was not crowded, so he moved slowly around the shelves, avoiding people and not standing for too long in one place. He got his things and made his way to the front, and got in line.
        The woman with her son stood in front of him. The kid was happy not being in school, but his demands for this and that made his mother sigh with irritation. He looked down and mentally measured the distance between himself and the two people. His cane was exactly four and a half feet in length. He stretched the cane and could touch the back of the mother's leg. He moved back a step and decided it was safe. Other shoppers and employees maneuvered around him as they too did their berst with social distancing. Some close encounters of the viral kind ws unavoidable, and he cringed when someone brushed against him. He figured he should try to get his groceries delivered, but he liked this store, though they did not have that option yet. So, it was a foray into danger that did not carry with it the thrill of adventure and daring. The line inched foward, as the clerks, behind protective glass barriers, scanned and bagged the purchases in paper bags. Finally his turn. He paid with his phone, waving it over the terminal like a man searching for water. It dinged a successful purchase and he got his bag and left.
        The bus did not come for 30 minutes. He had time to kill. He stopped at a nearby doughnut store and boudht a cinnamon roll and coffee. He made his way across the street, safely again, and ate his food slowly and sipped his hot coffee. The sun was shining, the fumes from the vehicles made his head fuzzy. He meditated on the rest of his family, who lived far away.
        He arrived home after a jolting bus ride and breathed deeply once he locked his door behind him. Even though he had gloves on, he peeled them off, thew them away and washed his hand vigorously in the scalding water from the tap.
        He felt exhausted. He would take a nap, then eat when he was rested. He fell into a sleep, dreaming of a time when he would take a road trop somewhere and enjoy solitude in a lonely place, appreciating nature.
   

Sunday, December 17, 2017

Jython: Dictionaries and list comprehension

I know I'm getting carried away with this list comprehension topic, but I'm finding it a lot of fun to see what else I can do with list comprehension. It also matches my other favorite topic (for another  day) of slicking and indexing. You will see some of it here. What I'm doing here is exploring more ways of doing list comprehension. I''m sure most of you know how to work with dictionaries.

Create a dictionary:

>>> D = {'a': 'aardvark', 'b': 'bear', 'c': 'cat', 'd': 'dog', 'e': 'elephant', 'f': 'fox', 'g': 'giraffe', 'h': 'hippo', 'i': 'insect'}

List comprehensions on a dictionary are a little more complicated than a list, but it's fairly easy.

>>> [x for x in D]
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
>>> [x for x in D.values()]
['aardvark', 'bear', 'cat', 'dog', 'elephant', 'fox', 'giraffe', 'hippo', 'insect']

Edited later:
>>> [x for x in D.items()]
[('a', 'apple'), ('b', 'balloon'), ('c', 'cat'), ('d', 'dog'), ('e', 'elephant'), ('f', ['fox'])]

>>> [x for x in D.items() if x[1] == 'elephant']
[('e', 'elephant')] # In this case, it sliced by element. Use x[0] to scan the keys.


You can use either .items() or .iteritems() to get key, value pairs,

Back to original post:

Say I want to get the last letter of each item in my dictionary values:

>>> [x[-1:] for x in D.values()]
['k', 'r', 't', 'g', 't', 'x', 'e', 'o', 't']

How about filtering:

# Get the elements where the last letter matches 't'.
>>> [x for x in D.values() if x[-1:] == 't']
['cat', 'elephant', 'insect']

As you see, slicing comes in handy with coding list comprehensions.

An earlier post, I eexplored how the dir() function can really be useful. Here's a little expansion on that topic:

>>> import os
>>> dir(os)
>>> len(dir(os))
110

I realized you really don't need a .startswith() or .endswith() call in a list comprehension to find matching elements. Just slice away!


Filter by first letter:
>>> [x for x in dir(os) if x[0] == 'e']
['environ', 'errno', 'error', 'extsep']

Outside of a list comprehensiuon, you would have to do this to get the first letter of an element.

>>> dir(os)[41]
'environ'
>>> dir(os)[41][0]
'e'

In the list comprehension, I didn't have to. Why? Because x already indexes the list, so I'm slicing each element to return any string beginning with 'e'.

If you need to know the index numbers to process later, you could:

>>> [dir(os).index(x) for x in dir(os) if x[0] == 'e']
[41, 42, 43, 44]

>>> [(dir(os).index(x),x) for x in dir(os) if x[0] == 'e']
[(41, 'environ'), (42, 'errno'), (43, 'error'), (44, 'extsep')]

As I've mentioned before, thinking a list comprehension through is simply a matter of putting the result you want first, then building the list comprehension to reach your result, as you can see in the example above. Now you have index intergers for all the elements beginning with 'e' from the list.

It's not necessary to use the keyword print inside the interactive session, but if you put a list comprehension in a script and need to show your result, put print before the list comprehension (e.g. print [x for ...])

I know there are programmers out there who are smareter and more experienced than me. As you see, I'm a quick learner and I relish the opportunity to continue learning.

I'm not shoinw off at all. Instead, I view this as a way to prod you and your ideas, so you can achieve your own success and sense of satisfaction at having done it. I am limited in my hearing and eyesight, but it doesn't stop me from doing what I can and stay busy in what I really enjoy.

Until later, happy coding!

Friday, December 15, 2017

Jython: Comprehending list comprehensions

This time, I'd like to discuss list comprehension. This is another tool used in Python and Jython. It's a very concise way of stepping through a list or a string, and processing information. You can build list comprehensions from the very basic to a complicated expression.

In an earlier post, I demonstrated a list comprehension at work with the dir() function, in returning information.

Here is a basic list comprehendion and they are enclosed in square brackets:

[expression for variable in sequence [if test-expression]]

test-expression is optional.

Let's see it in action:

>>>[x for x in ['one', 'two', 'three']]
['one', 'two', 'three']

To make it clear in my mind, I think of the first expression as the result I want, and build a list comprehension from that. Like so:

>>> [x.upper() for x in ['one', 'two', 'three']]
['ONE', 'TWO', 'THREE']

How about this?

>>> [x.startswith('t') for x in ['one', 'two', 'thre']]
[False, True, True]

It even does boolean expressions.

>>> a = 'ABC'
>>> word = ['Apple', 'Bird', 'Cat']
>>> [(x, y) for x in a for y in word if y.startswith(x)]
[('A', 'Apple'), ('B', 'Bird'), ('C', 'Cat')]

The above is an example of a nested list comprehension with an if test-expression. You noticed the result was list of tuples. You can put the result into a variable and print only what you need.

>>> result = [(x, y) for x in a for y in word if y.startswith(x)]
>>> result[0][1]  <<< here I indexed the tuple
'Apple'

>>> result
[('A', 'Apple'), ('B', 'Bird'), ('C', 'Cat')]

Or this:

>>> [x for (x, y) in result]
['A', 'B', 'C']

List comprehension can process files.

>>> [x for x in open('/home/patrick/script2.py')]
['import sys\n', 'print(sys.path)\n', 'x = 2\n', 'print(x ** 32)\n', '\n']

If you are using list comprehension in a script, and you want to show the results on the screen, just put the print before the list comprehension.

>>>print [x for x in open('/home/patrick/script2.py')]
['import sys\n', 'print(sys.path)\n', 'x = 2\n', 'print(x ** 32)\n', '\n']

Can you make a complex list comprehension? You can, with some work.

I was working on the Java class GregorianCalendar. I wanted to see if my system could disply other languages. So, I used the getAvailableLocales() method. However, this method returned a list of objects, not strings. I wanted to search for a particular county, by searching a partial string, but coudln't as U got an error saying x was not in the list.

As a workaround, I had to convert it to a string to search and have it return the index of the list element.. So, my original loop went like this:

for x in range(len(locale)):
    t = str(locale[x])
    if t.endswith('US'):
        subloc.append(locale[x])

After 3 hours or so, I was able to build a list comprehension that worked exactly as my loop:

subloc = [locale[x[0]] for x in enumerate(map(str, locale)) if x[1].endswith('US')]

Can you see how I did it? I will discuss enumerate() another day.

Is this really the Pythonic way? Maybe not, but list comprehension, when successful does marvel at the conciseness and simplicity of this powerful language.


List comprehensions allow Python/Jython do the work for you. This minimizes development time and is a great benefit of this language.

If you would like to see the full script, email me at psykiatris@gmail.com.

Till next time. Happy coding!