Python:
#!/usr/bin/env python # set, list, tuple, dict, deque, heapq, OrderedDict, defaultDict, Counter p = (4,5) # tuple packing x, y = p (x, y) = p # typle unpacking entry = [ 'name', 20, 1.1, (2017, 12, 31) ] a,b,c,date = entry # d = (2017, 12, 31) _, x, y, _ = entry # x = 20, y = 1.1 name, *_, (*_, date) = entry # name = 'name', date = 31 s = 'string' a,b,c,d,e,f = s # a='s', b='t', and so on *head, tail_one = s # head = 'strin' tail_one = 'g' # What are these? x = set(["Postcard", "Radio", "Telegram"]) y = {"Postcard","Radio","Telegram"} myList=[i*i for i in range(10)] myArray=[[1,2],[3,4]] cnt = Counter() for word in ['red', 'blue', 'red', 'green', 'blue', 'blue']: cnt[word] += 1 print(cnt) c = Counter(a=4, b=2, c=0, d=-2) def drop_first_last (list): fst, *mdl, lst = list return avg(mdl)
Perl:
# To get the same results... # sub pairwise_sum { my ($arg1, $arg2) = @_; my (@result) = (); @list1 = @$arg1; @list2 = @$arg2; $len = @list1; # same as length(@list1) $max_index = $#list1; for ($i=0; $i < length(@list1); $i++) { push (@result, $list1[$i] + $list2[$i]); } return (\@result); }
JavaScript:
var cars = ["Saab", "Volvo", "BMW"]; var cars = new Array("Saab", "Volvo", "BMW"); var name = cars[0]; document.getElementById("demo").innerHTML = cars[0]; // This is array var person = ["John", "Doe", 46]; // This is object var person = {firstName:"John", lastName:"Doe", age:46};
C++:
#include <iostream> using namespace std; int foo [] = {16, 2, 77, 40, 12071}; int another_foo [5] = { 16, 2, 77, 40, 12071 }; int jimmy [3][5]; // is equivalent to int jimmy [15]; // (3 * 5 = 15) #define WIDTH 5 #define HEIGHT 3 int jimmy [HEIGHT][WIDTH]; int n,m; int main () { for (n=0; n<HEIGHT; n++) for (m=0; m<WIDTH; m++) { jimmy[n][m]=(n+1)*(m+1); } }
No comments:
Post a Comment