• 0 Posts
  • 101 Comments
Joined 3 months ago
cake
Cake day: March 28th, 2024

help-circle
  • No problems. Learning a new concept is not stupid. So you are familiar with C. In C term, you are likely to do something like this:

    int a[10] = {0}; // Just imagine this is 0,1,2,etc...
    int b[10] = {0};
    for (int i=0; i < 10; i++) {
      b[i] = a[i]*2;
    }
    

    A 1 to 1 correspondent might looks like ths:

    a = range(10) # 0,1,2,etc...
    b = []
    for x in a:
      b.append(x*2)
    

    However in python, you can then simplify to this:

    a = range(10) # Same as before, 0,1,2,etc...
    b = [x*2 for x in a]
    
    # This is also works
    b = [x*2 for x in [0,1,2,...]]
    

    Remember that list comprehension is used to make a new list, not just iteration. If you want to do something other than making a list from another list, it is better to use iteration. List comprehension is just “syntactic sugar” so to speak. The concept comes from functional programming paradigm.


  • You can. Whatever the method returns will be the element of that list. So if for example I do this:

    def mul(x):
      return x*2
    
    list = [mul(value) for value in range(1,20)]
    

    It will have the same effect. But this:

    def mul(x):
      return
    
    list = [mul(value) for value in range(1,20)]
    

    Will just makes the list element all None

    Edit to add more: List comprehension works not from the range function. Rather, the range function is returning a list. Hence the name, “list comprehension”. You can use any old list for it.

    What it did under the hood is that it iterates each element on the list that you specify (the in ...), and applies those to the function that you specify in the very first place. If you are familiar with the concept of Array.map in other languages, this is that. There is also a technical explanation for it if it helps, but it requires more time to explain. Just let me know if you would like to know it.











  • Meanwhile someone somewhere is having issues with steam taking too much profit. Do note that even if a game is DELISTED from steam, you still can download the game on steam. Of course it is a different story with license revocation and that is a whole different can of worms. I don’t even know if steam allows the publisher to revoke a license for a game that the player already paid for just because the game is not supported anymore (a different case with breaking ToS/EULA).






  • Instagram by Meta has started using user generated content for their training data. Naturally users are upset about this and are flocking to a new platform named Cara made by an artist which has principle and are actively fighting for artist copyright. Cara uses Vercel to host their platform. The problem is that the sudden influx of users means bigger bills to pay to handle those traffic (I think they are billed around ~$96k). As of now, it is unclear how they will proceed to pay the bills. The creator of Cara didn’t want to compromise his stance by accepting any money willy-nilly, but also acknowledged that angel investors are not easy to find.