Re: Another question about pythonic syntax, yea!

2019-06-09 Thread AudioGames . net Forum — Developers room : pauliyobo via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

@28, I agree.

URL: https://forum.audiogames.net/post/439873/#p439873




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-09 Thread AudioGames . net Forum — Developers room : targor via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

@24 and 26, this is not true. Your for loop would only skip one index if you defined it like "for i in range(0, 10)". The syntax with "for item in list" never skips an index.

URL: https://forum.audiogames.net/post/439870/#p439870




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-08 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

@30, Ah. I see now.

URL: https://forum.audiogames.net/post/439617/#p439617




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-08 Thread AudioGames . net Forum — Developers room : The Dwarfer via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

@23noI got the following mixedx = [item for item in x if item!= 3]withx = (item for item in x if item!= 3)Put that in the console and you get a generator.

URL: https://forum.audiogames.net/post/439605/#p439605




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-08 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

@28, agreed, but LCs are only useful in particular scenarios. They're also limited.

URL: https://forum.audiogames.net/post/439593/#p439593




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-08 Thread AudioGames . net Forum — Developers room : Dragonlee via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

To all the people saying list comprehensions are bad because they are hard to understand, I beg to differ.The only reason you might think that is because you are used to the long form version and once you get used to  list comprehensions they are much much more readable and practical, because instead of drawing out the same info it is super compact. Also because it describes what you want instead of how to get what you want.LCs are even more useful for more complex  things like if you want to apply a function to transform the elements.# generate first 10 squaressquares10 = [num * num for num in range(1,11)] Super simple and  long form version is:>>> squares10 = []>>> for num in range(1,11):...  squares10.append(num*num)Way longer, easier to make a mistake, and less descriptive.nested LCs are also fantastic and pay off even more. To give  very simple example, imagine you want to generate a big list of possible names for bots or anonymous users, etc.>>> adjectives = ["Happy", "Angry", "Hungry"]>>> animals = ["Lion", "Zebra", "Hippo"]>>> names = [adj + animal for adj in adjectives for animal in animals]>>> names['HappyLion', 'HappyZebra', 'HappyHippo', 'AngryLion', 'AngryZebra', 'AngryHippo', 'HungryLion', 'HungryZebra', 'HungryHippo']P.S. I know there are other ways to enumerate possible combinations. This is mostly just an example, but one ting to keep in mind is that LCs are more versatile.

URL: https://forum.audiogames.net/post/439561/#p439561




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-07 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

@26, I'm not sure what your trying to convey here. An LC with a for loop is exactly the same as a normal for loop but more compact. You will get exactly the same results no matter how you do it.

URL: https://forum.audiogames.net/post/439382/#p439382




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-07 Thread AudioGames . net Forum — Developers room : majno via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

Sorry.  mistake in post 24. instead of != it should be ==.Post edited.Not all items are checked when an item is removed because if item in index 1 is removed the item number 2 in index will replace item number 1. so loop index will continue with next item number 2 skipping item number 2 which now is item number 1.

URL: https://forum.audiogames.net/post/439376/#p439376




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-07 Thread AudioGames . net Forum — Developers room : majno via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

Sorry.  mistake in post 24. instead of != it should be ==.Post edited.Not all items are checked when an item is removed because if item in index 1 is removed the item number 2 in index will replace item number 1. so loop index will continue with next item number 2 skipping item number 2 which now is item number 1.but yet is better use list comprehension for remove items from list.

URL: https://forum.audiogames.net/post/439376/#p439376




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-07 Thread AudioGames . net Forum — Developers room : majno via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

Sorry.  mistake in post 24. instead of != it should be ==.Post edited.but yet is better use list comprehension for remove items from list.

URL: https://forum.audiogames.net/post/439376/#p439376




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-07 Thread AudioGames . net Forum — Developers room : majno via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

Be careful when removing items using for loops.if you do some thing like this.x [1, 2, 3, 4, 5, 6, 7]for item in x:  if item == 3 x.remove(item)the index will skp the next element, so 4 will not be checked. if you havex = [1, 2, 3, 3, 4, 5]will only remove the first number 3 element in the list.for those cases is better use list comprehension instead for loops.

URL: https://forum.audiogames.net/post/439338/#p439338




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-07 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

@24, this is not correct. Running this in my python environment:>>> x = [1, 2, 3, 4, 5, 6, 7]>>> for item in x:...  if item != 3:...   x.remove(item)...>>> x[2, 3, 5, 7]if I use your other list (x = [1, 2, 3, 3, 4, 5]):>>> x = [1, 2, 3, 3, 4, 5]>>> for item in x:...  if item != 3:...   x.remove(item)...>>> x[2, 3, 3, 5]Case in point: all items are checked against all conditions and branches in the loop unless continue or break is executed in one of the conditional branches and that particular branches condition happens to be true.

URL: https://forum.audiogames.net/post/439355/#p439355




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-07 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

@24, this is not correct. Running this in my python environment:>>> for item in x:...  if item != 3:...   x.remove(item)...>>> x[2, 3, 5, 7]if I use your other list (x = [1, 2, 3, 3, 4, 5]):>>> x = [1, 2, 3, 3, 4, 5]>>> for item in x:...  if item != 3:...   x.remove(item)...>>> x[2, 3, 3, 5]Case in point: all items are checked against all conditions and branches in the loop unless continue and/or break is executed in one of the conditional branches.

URL: https://forum.audiogames.net/post/439355/#p439355




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-07 Thread AudioGames . net Forum — Developers room : majno via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

Be careful when removing items using for loops.if you do some thing like this.x [1, 2, 3, 4, 5, 6, 7]for item in x:  if item != 3 x.remove(item)the index will skp the next element, so 4 will not be checked. if you havex = [1, 2, 3, 3, 4, 5]will only remove the first number 3 element in the list.for those cases is better use list comprehension instead for loops.

URL: https://forum.audiogames.net/post/439338/#p439338




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-05 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

@20, this is not an example of a generator at all. A generator is an actual class -- class Generator to be exact. A generator requires that you call next() on it repeatedly until you get a StopIteration exception, which is the generators way of telling you "OK! I'm done!" An example of a generator is:def grange(max):
for i in range (max):
yield iIf I run this in my Python console, I get:That is what a generator looks like. a list comprehension is not a generator because if you enter something like[i for i in range (30)]or[i for i in range (1) if i %2 == 0]You will get back a list, not a generator. You could transform this generator into a list, but that would not only defeat the purpose of generators but be horribly inefficient, especially on massive generator sets. There are lots of places to learn about generators, so if your interested in them, go check some tutorials out.

URL: https://forum.audiogames.net/post/438847/#p438847




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-05 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

@20, this is not an example of a generator at all. A generator is an actual class -- class Generator to be exact. A generator requires that you call next() on it repeatedly until you get a StopIteration exception, which is the generators way of telling you "OK! I'm done!" An example of a generator is:def grange(max):
for i in range (max):
yield iIf I run this in my Python console, I get:That is what a generator looks like. a list comprehension is not a generator because if you enter something like[i for i in range (30)]or[i for i in range (1) if i %2 == 0]You will get back a list, not a generator. You could transform this generator into a list, but that would not only defeat the purpose of generators but be horribly inefficient, especially on massive generator sets.

URL: https://forum.audiogames.net/post/438847/#p438847




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-05 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

@20, this is not an example of a generator at all. A generator is an actual class -- class Generator to be exact. A generator requires that you call next() on it repeatedly until you get a StopIteration exception, which is the generators way of telling you "OK! I'm done!" An example of a generator is:def grange(max):
for i in range (max):
yield iIf I run this in my Python console, I get:That is what a generator looks like. a list comprehension is not a generator because if you enter something like[i for i in range (30)]or[i for i in range (1) if i %2 == 0]You will get back a list, not a generator. You could transform this list into a generator, but that would not only defeat the purpose of generators but be horribly inefficient.

URL: https://forum.audiogames.net/post/438847/#p438847




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-05 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

@20, this is not an example of a generator at all. A generator is an actual class -- class Generator to be exact. A generator requires that you call next() on it repeatedly until you get a StopIteration exception, which is the generators way of telling you "OK! I'm done!" An example of a generator is:def grange(max):
for i in range (max):
yield iIf I run this in my Python console, I get:That is what a generator looks like. a list comprehension is not a generator because if you enter something like[i for i in range (30)]or[i for i in range (1) if i %2 == 0]You will get back a list, not a generator.

URL: https://forum.audiogames.net/post/438847/#p438847




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-05 Thread AudioGames . net Forum — Developers room : thggamer via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

Here's another way to generate the same list. It may be more useful if you have a big list or if you have a big function to filter the elements.x = [1,2,3,4,5,6,7,8,9,3,3,4,5,4,3]y = filter(lambda value: value != 3, x)The filter function works calling the first parameter passed to it (the lambda function in this case). The lambda function returns true if x is not equal to 3. If it's 3, the lambda function returns false and filter won't include it in the new iterator.

URL: https://forum.audiogames.net/post/438827/#p438827




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-05 Thread AudioGames . net Forum — Developers room : Turkce_Rap via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

why do you use loop inside brackets?

URL: https://forum.audiogames.net/post/438818/#p438818




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-01 Thread AudioGames . net Forum — Developers room : The Dwarfer via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

@Post 1, that's because what you're doing is a generator.x = [item for item in x if item!= 3]Means:Give me a list wherein we iterate x. The iterator will be called item. So, let's put item in the list for items that do not equal 3.

URL: https://forum.audiogames.net/post/438064/#p438064




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-01 Thread AudioGames . net Forum — Developers room : sito via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

yeah. i noticed it while i was going through the python documentation. Honestly it seems that list comprehentions aren't that useful because you can only add and remove things in a list by making a new list. I think that if you're going to add something to a list you better off using the append method or if you're going to combine 2 lists together just use the extend methods. It might be good to use tlist comprehentions if your'e going to do really simple expressions with them but once you want to do more complicated code you're just better off writing stuff on seperat lines and using the built in methods for lists. Feel free to correct me if i'm wrong.

URL: https://forum.audiogames.net/post/438018/#p438018




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-06-01 Thread AudioGames . net Forum — Developers room : targor via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

I think if you want to use nested list comprehensions, you should really write the longer versions with for and if. While it might seem very cool to create a list and then imediately create another out of that first list in one single line, you'll never understand your code ever again  Besides, most times, you can avoid nested lc's by simply using more conditional statements in one lc.

URL: https://forum.audiogames.net/post/437946/#p437946




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-05-30 Thread AudioGames . net Forum — Developers room : sito via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

ok. But what about nested list comprehentions?  do they have their uses?

URL: https://forum.audiogames.net/post/437598/#p437598




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-05-29 Thread AudioGames . net Forum — Developers room : pauliyobo via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

sam, Thanks. Yes you're damn right.Talk about reading your posts before posting. Hm.

URL: https://forum.audiogames.net/post/437346/#p437346




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-05-29 Thread AudioGames . net Forum — Developers room : leibylucw via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

Oh, I understand what your signature means, but it was a little humorous to read "coding is not hard!" and then see a plethora of replies about how to do something with code. Lol.

URL: https://forum.audiogames.net/post/437316/#p437316




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-05-29 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

My signature is half sarcasm, half truth. While coding it’s self is not hard, you can learn the syntax in just a couple of days, it takes skill to put it all together and understand how to apply the concepts to whatever you want to do.  Furthermore, you are adding another layer of difficulty when allowing the user to input data, as they might not enter exactly what you want.

URL: https://forum.audiogames.net/post/437304/#p437304




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-05-29 Thread AudioGames . net Forum — Developers room : leibylucw via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

@amerikranian: I think it may be okay to say coding can be hard at times. 

URL: https://forum.audiogames.net/post/437289/#p437289




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-05-29 Thread AudioGames . net Forum — Developers room : Sam_Tupy via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

So paul, I just gotta give ya a friendly little poke here. Your examples are a bit broken, I figured you'd find it pretty amusing if I pointed it out  So your first one, for item in x: if item>3: x.remove(item) will remove every other item that is greater than 3. x = [item for item in x if item>3] will keep every item in the list that is greater than 3 and remove everything that is less than or equal to 3. I'm guessing in your first example with the if statements you were trying to remove everything greater than 3 and not every other thing, and I'm assuming you wanted to do the same in your second example  so I believe you wanted this.x=[1,2,3,4,5,6,7,8,9,10,11,12,13]#or, this ones for everybody x=list(range(1,14))#example 1for item in list(x):    if item>3: x.remove(item)#example 2x = [item for item in x if item<=3]Anyway this isn't me trying to be cocky or anything to anyone who would think so, I just know that if I did this Paul would also commence some friendly trolling in my direction 

URL: https://forum.audiogames.net/post/437271/#p437271




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-05-29 Thread AudioGames . net Forum — Developers room : Kyleman123 via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

Part of what bakes this tricky is that lists or arrays are actually pointers. Even though python touts the fact its a high level language that you don't have to worry about pointers and memory, in reality you kind of still do. personally i still like the more verbose version. its easier to read and much clearer as to what is actually going on. this goes for new programmers if you are collaborating with people and yourself 6 months or a ear down the road when you try and comprehend what the hell you wrote that one night. also good commenting can solve this too. if you are finding yourself writing a comment to explain what a tricky or clever bit or code does, there almost always will be a clearer way to write it. comments should explain why you wrote code like you did and your thought processes behind it.

URL: https://forum.audiogames.net/post/437156/#p437156




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-05-29 Thread AudioGames . net Forum — Developers room : zakc93 via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

List comprehension generates a new list, it doesn't modify the original. It's useful if you want a subset of an existing list without wanting to modify that list. If you assign the new list to the same variable though then you could just as well remove it from the original, it doesn't really matter. Post 9 also has a good point, saying y=x in that example won't actually create a copy of x, it will only create a new reference to x. So if you modify y, the same will happen to x. If you want to create a new copy you need to do something like y =x[:], where the colon is used to slice lists (but using it without any other parameters will return the whole list).

URL: https://forum.audiogames.net/post/437132/#p437132




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-05-28 Thread AudioGames . net Forum — Developers room : leibylucw via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

I think this question is less about syntax and more about fundamentals of programming.Whenever you create a list in memory, you assign it a reference variable. If you make a modification to that object in memory, what you're really doing is copying its data in tandem with whatever change you made and creating a new object in memory. Reference variables point to memory addresses rather than objects (or data to make this less confusing). This is seemless to us, and it's all under the hood so to speak. Take the the following code:x = [1, 2, 3, ...]y = xBoth x and y reference the same list. All you did was assign y to the same memory address that x is assigned to.I highly recommend looking into the object-oriented side of programming, especially if you're using any of the more modern-day languages like Python.

URL: https://forum.audiogames.net/post/436956/#p436956




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-05-28 Thread AudioGames . net Forum — Developers room : pauliyobo via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

@4 is really a preference really.List compreensions are quick ways to create new lists from an other list in one line.Suppose we have this listx = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16]Instead of spending more than 3 lines of code to do an action such as removing elements from the list you can just generate the new list from the old list.Soinstead of doingfor item in x: if item>3:  x.remove(item)you can just do it in one linex = [item for item in x if item>3]This code is equivalent to:def compreension(x): for item in x:  if item>3:   x.remove(item) return xYou are not forced to use it. It is a preference really.

URL: https://forum.audiogames.net/post/436927/#p436927




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-05-27 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

So is that a bad thing? Why would I want to use some other  method?  When would you use list comprehension?

URL: https://forum.audiogames.net/post/436890/#p436890




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-05-27 Thread AudioGames . net Forum — Developers room : stewie via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

@5 That is what is happening@3 That code is a list comprehension, which is kind of a for loop. The original list is not being changed directly by the list comprehension at all. This should be clearer with a slightly modified example.x = [1,2,3,4,5,6,7,8,9,3,3,4,5,4,3]y = [item for item in x if item!=3]The list comprehension is only interacting with the original because you told it to (by referencing x directly). All this is doing is repeating the item variable through x. If item is not equal to 3, it adds the number from x to the new list. If item is 3, it just does nothing because the condition if item != 3 is false. The two lists (x and y) are two completely different objects in the same way as two ints are different, even though they may hold the same number as a value. To remove all the 3's from x directly, you'd have to call some method on x, such as x.remove(3) multiple times or do it some other way.The reason the list changed originally in your example was because you set x equal to the new list.

URL: https://forum.audiogames.net/post/436888/#p436888




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-05-27 Thread AudioGames . net Forum — Developers room : stewie via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

@5 That is what is happening@3 That code is a list comprehension, which is kind of a for loop. The original list is not being changed directly by the list comprehension at all. This should be clearer with a slightly modified example.x = [1,2,3,4,5,6,7,8,9,3,3,4,5,4,3]y = [item for item in x if item!=3]The list comprehension is only interacting with the original because you told it to (by referencing x directly). All this is doing is repeating the item variable through x. If item is not equal to 3, it adds the number from x to the new list. If item is 3, it just does nothing because the condition if item != 3 is false. The two lists (x and y) are two completely different objects in the same way as two integers are different, even though they may hold the same number as a value. To remove all the 3's from x directly, you'd have to call some method on x, such as x.remove(3) multiple times or do it some other way.The reason the list changed originally in your example was because you set x equal to the new list.

URL: https://forum.audiogames.net/post/436888/#p436888




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-05-27 Thread AudioGames . net Forum — Developers room : dardar via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

ok, sorry for the double post, but I really, still don't get what the purpose is.Like, I'm reading the code and... just not getting it.Maybe this is a learning thing for me.Are you saying list1 is this, and you want list2 to be list1 but without the 3's?I think the shorthand confused me, again, sorry for the double post

URL: https://forum.audiogames.net/post/436877/#p436877




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-05-27 Thread AudioGames . net Forum — Developers room : dardar via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

So I have my own question here.The code above looks very, very compact.Why not use this?l=[1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2,1]for x in l: if(x==3):  l.remove(x)I mean you can also do:while(3 in l): l.remove(3)but eh whatever. Same difference.

URL: https://forum.audiogames.net/post/436874/#p436874




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-05-27 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

Right, but what happens to all the elements that contain three? Are they simply gone?  To put it in another way, what is the difference between building a copy of a list and removing an item from it

URL: https://forum.audiogames.net/post/436873/#p436873




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-05-27 Thread AudioGames . net Forum — Developers room : stewie via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

you use [a for item instead of [item for item. Think of it like a for loop, the variable being referred to has to be the one looping through the list. Also keep in mind that you aren't removing anything from the list when using a list comprehension. In this case you're building a copy of the old list that does not contain 3.

URL: https://forum.audiogames.net/post/436860/#p436860




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Another question about pythonic syntax, yea!

2019-05-27 Thread AudioGames . net Forum — Developers room : stewie via Audiogames-reflector


  


Re: Another question about pythonic syntax, yea!

you use [a for item instead of [item for item. Think of it like a for loop, the variable being referred to has to be the one looping through the list.

URL: https://forum.audiogames.net/post/436860/#p436860




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector