Johnaudi wroteC#:
long a = 0, r = 0;
for (int i = 1; i < 1001; i++) r = r * i;
for (int i = 0; i < r.ToString().Length; i++) a += r.ToString()[i];
r=0 and always will be.
And 1000! Is a big number log10(1000!)=2568 which means it contains over 2560 digits, while long can't handle more than 20bytes.
Adnan wroteFeel free to point out my bad habits. Thanks !
The biggest issue I have with your code is that i, li and lii are terrible variable names. Unfortunately naming variables is particularly difficult when working on math problems. So try to include a description of what you're trying to do. Currently my favorite way of dealing with this problem is doctest.

As mentioned, your code duplicates existing internal functions available in the standard library. You should use them whenever possible. In your case check out range (or xrange if you're using python 2) and the factorial function of the math module.

However, just as you mention, you're using lists when you shouldn't. A list is expensive and should be avoided when possible. Can you think of a way to rewrite your code without creating these lists?
What's a lambda?
Adnan wroteI've came across people using lambda but I still don't understand how to use it, I'll read some docs / tutorials to learn it.
A lambda is a fancy name for a fairly simple concept called anonymous functions. Here's how Python deals with it.

First you have to understand that in Python, a function is an object just like int, str, list, tuple, dict or any other kind of object you came across. So just like any object, it can be assigned to a variable. Look at this:
# Let's define a simple function
def say_hello(name):
    return "Hello " + name

assert say_hello("Adnan") == "Hello Adnan"


# Now let's create a new variable pointing to this function
greet = say_hello

assert greet("Adnan") == "Hello Adnan"
lambda is just an operator that creates a new function without associating it to a variable name (hence the term "anonymous"). Here's how it can be used:
lambda <comma-separated list of arguments>: <value to be returned>
For instance, here's another way to define the say_hello function:
say_hello = lambda name: "Hello " + name
assert say_hello("Adnan") == "Hello Adnan"
Why is this useful and how to use it is a complicated topic; some programmers think that lambdas are themost powerful programming technique, while others believe they're evil and should never be used. On top of this, for better or worse, Python has added some restrictions by design to the lambdas that make them limited. If you're interested in the subject, open a new topic where we can discuss the use of lambdas specifically.

If you want to read more, I wrote a small article a while back that details a good use for lambdas.

What's yield?
Adnan wrote (and lots of "yield" here and there, not sure what that is yet, but the word is catchy).
The short answer is that yield is a keyword that allows the creation of generators. So before going further you should note this:

Python generators are an advanced topic. Even programmers with several years of experience might struggle with the concept upon discovering it. So it's normal if you find it a bit difficult to understand at first.

I'm not going to explain how they work, but I'm going to point you to relevant documentation: The most relevant one (just like anything in Python) is the PEP. In our case it's PEP 255: Simple Generators. However I find this PEP in particular a little difficult to read. So I found that this SO question and its answers do a good job at explaining it.

Again, if you have questions, open a new topic and we'll discuss it there :)
NuclearVision wrote
Johnaudi wroteC#:
long a = 0, r = 0;
for (int i = 1; i < 1001; i++) r = r * i;
for (int i = 0; i < r.ToString().Length; i++) a += r.ToString()[i];
r=0 and always will be.
And 1000! Is a big number log10(1000!)=2568 which means it contains over 2560 digits, while long can't handle more than 20bytes.
Oh oops! Sorry typo...

I'll edit it.

There:
BigInteger a = 0, r = 1;
for (int i = 1; i < 1001; i++) r *= i;
for (int i = 0; i < r.ToString().Length; i++) a += r.ToString()[i];
Biginterger is not enough I think.
Still trying to come up with a more clever solution.
NuclearVision wroteBiginterger is not enough I think.
Still trying to come up with a more clever solution.
Is the answer 133803?
@john it's 10539, I solved it with python a year ago, in python variables are not declared I even remember printing the 1000!, it does not overflow as easily as C and its derivatives.
edit: John I studied your code and I think it's rather summing strings than integers.
I'm not sure but here is my hypotheses:
1000! In bigint is equal to a six digits number (due to overflow); you made a string out of this number then added it to a.
So if my hypotheses is true, if you do bigint r; then print r it should be something similar to 133xxx (the solution you have which I don't remember ).
in php...
array_sum(str_split(gmp_strval(gmp_fact(1000))));
@Johnaudi

You are summing the ascii value of the digits and not the digit itself.
Change
a += r.ToString()[i];
to
a = a + r.ToString()[i] - 48;
48 is the ascci value of 0, the others are 49,50,etc...
NuclearVision wrote@ra8 hello friend!
Don't strings sum up in c#?
Those are characters that he's adding up, not strings.
check http://ideone.com/hLUqOb
Ok cool, thanks for helping us! now I know c# is really different from c++.