qwertyuu's Profile User Rating: -----

Reputation: 2 Apprentice
Group:
Active Members
Active Posts:
66 (0.05 per day)
Joined:
31-July 12
Profile Views:
1,836
Last Active:
User is offline Jan 15 2016 04:46 PM
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Windows
Favorite Browser:
FireFox
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
0

Latest Visitors

Icon   qwertyuu I know C#!

Posts I've Made

  1. In Topic: How would one achieve an inline 'but' in python?

    Posted 13 Jan 2016

    View Postandrewsw, on 13 January 2016 - 10:06 AM, said:

    View Postqwertyuu, on 13 January 2016 - 05:01 PM, said:

    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!

    I think 'but' is still slightly confusing/ambiguous. excluding (15, 16) is clearer.


    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?

    View Postandrewsw, on 13 January 2016 - 10:14 AM, said:

    View Postqwertyuu, on 13 January 2016 - 05:03 PM, said:

    View Postandrewsw, on 13 January 2016 - 09:58 AM, said:

    Again adding to the list of available approaches, using set comprehension:
    print({x for x in range(1, 19)} - {15, 16})
    


    Quick question:
    Does this also only work with distinct values? I read somewhere that sets weren't very good with duplicates

    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.
  2. In Topic: How would one achieve an inline 'but' in python?

    Posted 13 Jan 2016

    View Postandrewsw, on 13 January 2016 - 09:58 AM, said:

    Again adding to the list of available approaches, using set comprehension:
    print({x for x in range(1, 19)} - {15, 16})
    


    Quick question:
    Does this also only work with distinct values? I read somewhere that sets weren't very good with duplicates
  3. In Topic: How would one achieve an inline 'but' in python?

    Posted 13 Jan 2016

    View Postandrewsw, on 13 January 2016 - 09:51 AM, said:

    They 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!
  4. In Topic: How would one achieve an inline 'but' in python?

    Posted 13 Jan 2016

    View Postandrewsw, on 13 January 2016 - 09:38 AM, said:

    There 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.
  5. In Topic: How would one achieve an inline 'but' in python?

    Posted 13 Jan 2016

    Well 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.

    EDIT

    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:
    [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,18]

    How feasible is this? Because I think that would bring some kind of universal understanding of an 'except this' in a list or logic.

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Years Programming:
1
Programming Languages:
C#

Contact Information

E-mail:
Private

Friends

qwertyuu hasn't added any friends yet.

Comments

qwertyuu has no profile comments yet. Why not say hello?