7
In PHP, when we want to make a array
alphabet letters, we can use the function range
.
Example in PHP:
$letras = range('a', 'z');
Upshot:
Array (
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
[5] => f
[6] => g
[7] => h
[8] => i
[9] => j
[10] => k
[11] => l
[12] => m
[13] => n
[14] => o
[15] => p
[16] => q
[17] => r
[18] => s
[19] => t
[20] => u
[21] => v
[22] => w
[23] => x
[24] => y
[25] => z )
And it’s also possible to do this through for
for ($a = 'a'; $a != 'aa'; $a++) echo $a;
Upshot:
abcdefghijklmnopqrstuvwxyz
But in Python, when I try to do this through the function range
, an error is returned.
Python example:
range('a', 'z');
Traceback (Most recent call last): File "", line 1, in Typeerror: range() integer end argument expected, got str.
So the question is: As simple as possible, how could you generate a list of letters of the alphabet in python
?
Stop it! Damn, that surprised me! I’m going to migrate for good
python
– Wallace Maxters
Hahaha.. This also surprised me :D
– Math
You need to know the web frameworks, I suggest starting with Flask. PHP never again :P
– Math
Note that in general, you don’t even need to create this list- you can use the.ascii_lowercase string directly - since strings work as strings.
– jsbueno
Hahaha also surprised me :D
– GlaucioFonseca