Appending to a list gives ‘int’ object has no attribute ‘append’

Traceback (most recent call last): File “/home/shinigami/prac5.py”, line 21, in a[i].append(p) AttributeError: ‘int’ object has no attribute ‘append’ Your variable a is a list of integers. When you write a[i].append(…) you’re trying to call an append method on an int type, which causes the error. Writing a.append(…) is fine because a is a list, but as soon as you index into the list, you’re dealing with with the numbers within the list, and they … Read more

ArrayList vs List<> in C#

Yes, pretty much. List<T> is a generic class. It supports storing values of a specific type without casting to or from object (which would have incurred boxing/unboxing overhead when T is a value type in the ArrayList case). ArrayList simply stores object references. As a generic collection, List<T> implements the generic IEnumerable<T> interface and can be used easily in LINQ (without requiring any Cast or OfType call). ArrayList belongs to the days that C# didn’t have … Read more

What does the “x for x in” syntax mean?

This is just standard Python list comprehension. It’s a different way of writing a longer for loop. You’re looping over all the characters in your string and putting them in the list if the character is a digit. See this for more info on list comprehension.

HashSet vs. List performance

A lot of people are saying that once you get to the size where speed is actually a concern that HashSet<T> will always beat List<T>, but that depends on what you are doing. Let’s say you have a List<T> that will only ever have on average 5 items in it. Over a large number of cycles, if a single item … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)