Reputation: 2 Apprentice
- Active Members
- Active Posts:
- 66 (0.05 per day)
- 31-July 12
- Profile Views:
- Last Active:
- Jan 15 2016 04:46 PM
- Who Cares
- OS Preference:
- Favorite Browser:
- Favorite Processor:
- Favorite Gaming Platform:
- Your Car:
- Who Cares
- Dream Kudos:
Posts I've Made
Posted 13 Jan 2016
You're right. 'excluding' would be exactly what I want. This or a simpler one, 'excl'. Do you know how I could get started getting in contact with the python devs to get this idea rolling?
Not very good with duplicates?! The whole purpose of a set is that it, specifically, does not allow duplicates. Sets and Frozensets
In my statement, it is not significant that the set comprehension produces the same resultset as the list-comp. version; what is significant is that the result is a set, so that the set difference operator '-' can be used with it.
Yes, I never had to use a Set before so I couldn't know. Thank you for the informative link. This is such a great forum and you're very kind to help me with this.
Posted 13 Jan 2016
Posted 13 Jan 2016They are cryptic (like anything) on first meeting, but elegant IMO once we understand them.
but I am not attempting to dissuade you from your mission />
Thanks for understanding. Bear in mind that my first idea was to let 'very first time users' have a better grasp of logic before they actually dive in the code (I'm really not saying list comprehension is bad or that it shouldn't be used. I use it all the time and even with a but statement I'd use them). I think something along the 'but' statement would make python more readable (because it's one of the first goals of python) and more approachable, lowering the time needed to get into more concrete problems and negating the time you'd need to grasp all concepts around lists. I've been around beginners a lot lately and I think such a keyword would be a game changer for newcomers. Also, even after years of programming, I'm sure even pros could use such a simple and elegant 'but' keyword to achieve their simple goal without diving into list comprehension, much like we did with the 'in' statement, or inline ifs. All those are 'unnecessary' until you use them. Then they become part of daily coding life.
I really want this idea to develop and make way into the language. Not that it will, but I really want to. Thank you all again for helping me!
Posted 13 Jan 2016There are list comprehensions
y = [x for x in range(1, 19) if x not in (15,16)] print(y) for x in y: print(x)
This is exactly what I'm trying to avoid. The cryptic mess that is list comprehension (at least, for such a simple task as removing 2 elements from a list).
My goal is to imagine a NEW operator that could take care of the most basic task of removing part of a list without diving into those. If you need more control, then, the 'but' statement would be of no use and then you'd need list comprehension. I'm trying to make python even more python-er
maybe something along the lines of
def but(ORIGINAL_LIST, TO_REMOVE): return [x for x in ORIGINAL_LIST if x not in TO_REMOVE]
What I had coded already was this:
class lst(list): def __sub__(l, r): return lst(filter(lambda v: v not in r, l))
which did the exact same thing, but let me use it as a more natural approach:
for i in lst(range(19)) - lst([15, 16]): #where '-' is the 'but' print i
could work, but keep in mind that I want the operator to also work with BOOLean logic.
Posted 13 Jan 2016Well I couldn't have dreamed of a better response. Thank you!
You're right about except. I couldn't make my mind at first! Though, I think using a keyword like 'but' or 'except' would make this even better for reading. But I doubt they'll change anything for such a simple difference.
Now that we have the BOOL problem solved, I think it's time to merge 2 ideas together.
The 'but' or 'except' statement would also work for LISTS.
Here's my second idea:
for i in range(19) but [15, 16]: print i
Still following the same logic, the latter would remove [15, 16] from the range(19), hence resulting in a list like this:
How feasible is this? Because I think that would bring some kind of universal understanding of an 'except this' in a list or logic.
- Member Title:
- D.I.C Head
- Age Unknown
- Birthday Unknown
- Years Programming:
- Programming Languages:
qwertyuu hasn't added any friends yet.