0
Good morning guys, I started learning Python a few days ago and, doing some tests with lists around here I got some questions.
1 - In PHP I can create an array by defining the indexes of its values:
<?php
$array = array( 1 => 'Jan', 2 => 'Fev', ..., 12 => 'Dez' );
?>
But I couldn’t find a way to do the same in Python, can I? In the researches I did I ended up finding information about the index() function, which is not quite what I look for.
2 - These days, looking at some code around here, I found the following line:
your_list = [1,2,3]
a = [i for i in your_list]
a = [x+i for i in your_list for x in a]
print( a )
I understood what happens, basically it returns a list with the possible sums between the values in your_list: [1+1, 1+2, 1+3, 2+1, 2+2, 2+3, 3+1, 3+2, 3+3]. What got me curious here was how to rewrite the third line to separate the two for.
Thanks in advance.
Thanks for the help, I will search more about List Comprehension
– Rafael S.