1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri Mar 16 17:08:52 2018 @author: beast """ def version1(): a=['a','b','c','d','e'] # list 1 b=['a','b','c','d','e','f','g','h'] # list 2 c=[k for k in (a)if (k in (a) and k not in (b))] # include unique item from list 1 : items are (list1-list2)(set thoery) d=[l for l in (b) if l in (a ) and l in (b) or (l not in (a) and l in (b))] #include all the comman from list 1 and unique from list 2 lst=c+d # append above two comprehensed list to get union of list1 U list2 lst.sort() # not neccessay but makes list easy to understand (sorting in ascending order ) print("\n\na=",a) print("\n\nb=",b) print("\n\nunion=",lst) return lst # make it easy to import and use e.g import union_beast.py and then call union_beast.version1() it will return this union of list def version2(): a=['a','b','c','d','e'] # list 1 b=['d','e','f','g','h'] # list 2 c=[] for k in range (max(len(a),len(b))):# max return maximum number among two or more number so we iterate over max of length of both the list if k <len(a) and a[k] not in (b) : # if length of a is greater than current indexing and element at kth index is not present in list b (ie get List1-list 2 item) c.append(a[k]) # if item is unique to list 1 then append to result list (here c) if k <len(b) and b[k] not in (a) :# same as above logic but here we get item unique to list 2 (here list b) c.append(b[k]) # same append to result list (here c) if k <len(b) and b[k] in (a) : # now add the comman item to list (this is vital step as we only add only one instance of item that are both present in list 1 and list 2) eg if 2 is present in list 1 and list 2 we add only one 2 to result list c.append(b[k]) # append to result list (here c) c.sort() # not neccessary but make the result more eye catchy print("\n\na=",a) #print list 1 print("\n\nb=",b)#print list 2 print("\n\nunion=",c) #print the result if __name__=="__main__": # used to run the function via main loading ...i.e if the module is not imported print("\n----------by version 1------------\n") version1() print("\n\n------------by version 2------------") version2() |
Twitter has always suffered an image problem and is not usually taken very seriously by the general public. Its name doesn’t help with some people even saying that ‘Twitter is for twits’. Despite this glamor and brand problem this has not held back its growth after its humble origins and launch in 2006. Since then Twitter has gained popularity worldwide and is estimated to have 225 million users, generating 65 million tweets a day and handling over 800,000 search queries per day. It is sometimes described as the “SMS of the Internet” and its 140 character limit keeps the messages short and simple. Its attraction as a social web media platform is maybe in its simplicity and real time messaging that enables breaking news and information to hit the web instantly without filt30 Terrific Twitter Facts and Figures:- Twitter was created in March 2006 by Jack Dorsey and launched in July of that year. Twitter’s origins lie in a “day long brainstorming session” that was held by board...
Comments
Post a Comment
share your thoughts ....