Make let and let's one-line programming

There are times when you want to write in one line using list comprehension, but you want to define variables, right? Yes, I would be happy if I could write it like this.

homu.let(lambda mami: (mami[0], mami[1] if len(mami) > 1 else None))

It is a story to realize it in half.

Reference: Implementing a LINQ-like list processing library in Python --TIM Labs

| It seems that you can do something like an extension method by overloading the operator. You can also make let using the same method!

class let:
	def __init__(self, action):
		self.action = action
	
	def __ror__(self, source):
		return self.action(source)

Then

homu | let(lambda mami: (mami[0], mami[1] if len(mami) > 1 else None))

I can write! Nice!

Recommended Posts

Make let and let's one-line programming
Let's make a simple game with Python 3 and iPhone
Let's make a Mac app with Tkinter and py2app
Let's make a Discord Bot.
Coordinator and integer linear programming
Let's make an Errbot plugin
Let's make Splatoon AI! part.1
Let's make dice with tkinter
Let's make a rock-paper-scissors game