'for' loop explanation request


Mark
26/4/2016 6:52 am
HOME ยป Web Development

I recently started learning python. So I wrote some small code, this code asks for 2 sizes of lists, creates 2 lists with random integers from 0-9 and then spits out the intersection between two lists.

The last "for" loop - I had trouble with it because at first my "intersection" list had repetitions, then I looked up for an answer and got what I have now, it works, however I don't know why. My problem is grasping how "for i in l1 and in l2" works? I know that "for i in range(k)" is going through the numbers 0-k but this strange for loop with the "and" operator just puzzles me.

l1 = []
l2 = []
C = []
s1 = int(input("Your 1st list size->"))
s2 = int(input("Your 2nd list size->"))
for i in range(s1):
    from random import randint
    k = (randint(0,9))
    l1.append(k)
print("First List ->" , l1)
for i in range(s2):
    from random import randint
    k = (randint(0,9))
    l2.append(k)
print("Second List ->" , l2)
for i in l1 and l2:
    if i in l1 and l2:
        C.append(i)

print("Intersection ->" , C)

Please let me know if there is another place to submit such questions(if here is not for suitable).


Related to : 'for' loop explanation request
'for' loop explanation request
26/4/2016 6:52 am by Mark in Web Development

I recently started learning python. So I wrote some small code, this code asks for 2 sizes of lists, creates 2 lists with random integers from 0-9 and then spits out the intersection between two lists.

The last "for" loop - I had trouble with it because at first my "intersection" list had


Request for a more detailed explanation
by bigben2wardpitt in Web Development

Hi everyone,
I'm new here and trying to read through everything because I know how annoying it is when newbies ask the same questions over and over and over.
I've been reading the One Click All in One LG Spectrum Root thread and have downloaded what appears to be the latest version fr
Explanation of sizeof(...) request
by TCH in Web Development

Im aware of what sizeof(...) does, what I would like to know is if
sizeof(...) is compiled in or a function thats executed at run-time.
Like for example
{
int a;
printf("a is %d bytes", sizeof(a));
}
would this yield the same "machine code" as i
javascript - explanation request of a behaviour
31/12/2014 12:20 pm by Pakistan in Web Development

I witnessed this behaviour from JavaScript which I found interesting, but I don't know how to search for the reason of it so I have the following question.

As far as I know multi-line statements work in JavaScript, for example:

var text = "abc" + 
"xyz";


Request for explanation of an idiomatic D2 construct
by Charlie98 in Web Development

I often come accros the following construct that I don't quite grasp in a D2 source code:


alias uint SymbolRef;
struct SymbolTable {
alias entries this;
SymbolRef startSymbol;
Symbol[] entries;
}

What does imply the alias en


ASP .NET 2.0 special folders explanation request
by Hai Nguyen in Web Development

Hello All,
I noticed in the ASP.NET beta 2 that we have more special folders. Can
I get some clarification regarding these folders? I am just making sure
of the intent.
Thanks in advance,
Bob Hanson
*** Sent via Developersdex http://www.developersdex.com ***
N
How to Request a Letter for Explanation of Benefits
by lietkynes in Web Development

You received a mysterious bill pertaining to your hospital visit last month. It has some information about a test that the hospital administered, but you don't understand what the bill means and why the insurance hasn't paid it. Scenarios like this one happen all the time. The best thing to do if yo
Need explanation: while loop
by kivava in Web Development

Hey guys,
Im learning C++ in college now and I though Id check some books for extra material, so Ive been checking "C++ Primer Plus" and theres the next example:
[code]
// and.cpp -- using the logical AND operator
#include <iostream>
const int ArSize = 6; TAGS: Need explanation while loop
Explanation about for loop
by kpkp in Web Development

can any one help me explaining for loop and its execution and its
syntax with a simple example.
Jan 12 07 #1 Post Reply Share this Question 3 Replies (adsbygoogle = window.adsbygoogle ||
Explanation of For each loop
by ElMonoDelMar in Web Development

Hi all,
I have a misunderstanding regarding foreach loops which I can't resolve, nor can I figure out how to get the code right to do what I want.
First I'm storing the results of a Mysql query into an array.
The results contain multiple rows, each row has several that pertain to it--


HD Wallpapers
3D
3D Abstract
City
Celebrities
Indian Celebrities
Cars
Travel
Girls
Animals Birds
Movies
Sports
Black White
Nature
Planes
Anime
Food Drink
Dreamy Fantasy
Architecture
Games
Space
Holidays
Flowers
Love
Artistic
Baby
Beach
Bikes Motorcycles
Macro
Computers
Vector
Funny
Army
Textures
Brands
Misc
Music
Other
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .