Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Python

Name: Anonymous 2013-03-25 17:14

Hey /prog/,

How can I do this?

We can represent tables in Python as lists of lists as the following:

X0 Y0
X1 Y1

We could use [["X0", "Y0"], ["X1", "Y1"]].

Write a function called merge_tables, that consumes two list of lists (table1 and
table2) and produces a list of lists that corresponds to the merged version of the two
consumed tables. In order to merge the tables we follow certain rules:

• The first column of both table1 and table2 is called the key and the same key
value can occur in both tables or in only one table.

• If table1 has m columns and table2 has n columns then the produced table
will have m+n-1 columns (the key should not be repeated twice in the
produced rows).

• The columns in the produced table should be in the same order as all the
columns in table1 followed by all but the first column in table2.

• Every row in a table has the same number of columns.

• The rows in the produced table do not have a specified order.

• If the the same key value occurs in both tables the two rows should be merged
in the produced table. The key links the two tables.

• There may be multiple rows in table1 or table2 which contain the same key.
In this case the rows should be merged with all rows from the other table with a
matching key. See key “D” in the example below.

• If a key in one table has no match in the other table the value None should be
placed in the missing column fields. The first column in the produced table
should always be the key.

• If both consumed tables are empty then the empty table is produced.

• If only one of the consumed tables is empty then either table1 or table2 is
produced, whichever one is non-empty.

With the example,

merge_tables([["A", 11], ["B", 22], ["D", 33], ["D", 44], ["E", 55]], [["A", True, 5.0], ["B", False, 8.0], ["C", True, 4.0], ["D", False, 2.0], ["D", True, 1.0]]) =>

[["A", 11, True, 5.0],["B", 22, False, 8.0], ["D", 44, False, 2.0], ["D", 44, True, 1.0], ["D", 33, False, 2.0], ["D", 33, True, 1.0], ["C", None, True, 4.0], ["E", 55, None, None]]

Name: Anonymous 2013-03-25 17:19

Easily.

Name: Anonymous 2013-03-25 17:36

Is this from the new shitty FIOC based SICP?
Just use Scheme, like a real programmer would, and not a toy language like FIOC.

Name: Anonymous 2013-03-25 18:05

Name: Anonymous 2013-03-25 19:05

Just use Python as an interface to SQL.

Name: ^^ 2013-03-25 21:42

for b in t2:
  done = false
  for a in t1:
    if b[0] == a[0]:
      a += b[1:]
      done = true
  if not done:
    t1.append(b)

Name: Anonymous 2013-03-25 22:09

Hmm...

Name: Anonymous 2013-03-25 22:16

>>6
This outputs
[['A', 11, True, 5.0], ['B', 22, False, 8.0], ['D', 33, False, 2.0, True, 1.0], ['D', 44, False, 2.0, True, 1.0], ['E', 55], ['C', True, 4.0]]

it should output
[["A", 11, True, 5.0],["B", 22, False, 8.0], ["D", 44, False, 2.0], ["D", 44, True, 1.0], ["D", 33, False, 2.0], ["D", 33, True, 1.0], ["C", None, True, 4.0], ["E", 55, None, None]]

Name: Anonymous 2013-03-25 22:47

>>6
Nice one, retard!

Name: Anonymous 2013-03-26 0:41

>>7 gets it ^^

Name: Anonymous 2013-03-26 12:12

Name: Anonymous 2013-03-26 12:48

this is an easy one-liner in javascript

why is python even relevant?

Name: Anonymous 2013-03-26 13:45

>>12
I'm interested in knowing how this is done in Javascript. Wanna shed some light?

Name: Anonymous 2013-03-26 14:07

>>12
this is an easy one-liner in python

why is javascript even relevant?

Name: Anonymous 2013-03-26 14:07

ספר זה מלמד JavaScript צעד אחר צעד. ספר זה מלמד תכנות ומיועד למי שלמד HTML בעבר ורוצה לדעת לתכנת אתרים דינמיים. הספר מתחיל מתוכניות פשוטות מאוד, ובכל נושא יש דוגמאות, תרשימים וכלים העוזרים להבנת הנושאים. למי שלמד את הפרקים הראשונים או שלמד JavaScript בעבר, ספר זה מלמד תיכנות ברמה גבוהה ושימוש בספריות JavaScript.

שפת JavaScript נמצאת בשימוש במיליארדי דפים ברשת התורמת לשיפור העיצוב, לתקיפות טפסים, זיהוי דפדפנים, יצירת אנימציות וכו'. נוסף לכך, ככל שהזמן הולך, הישומים באינטרנט הופכים לפופולריים יותר. דוגמאות טובות לכך הם השירותים של גוגל כמו גוגל דוקס.

Name: Anonymous 2013-03-26 14:13

>>15
What an horrible language

Name: Anonymous 2013-03-26 14:13

>>16
I know, right.

Name: Anonymous 2013-03-26 14:14

>>16
What an shitty english

Name: Anonymous 2013-03-26 14:14

>>16
Dumb goy.

Name: Anonymous 2013-03-26 14:17

>>16
Please don't detonate yourself!

Name: Anonymous 2013-03-26 14:24

>>20
I'm a spic, we don't go boom.

But really, is awful... not like beautiful japanese, or even korean, by far a superior and prettier language.

Name: Anonymous 2013-03-26 14:32

>>21
I'm a spic too, and I'm the I love JEWS guy.

Hebrew is kind of intriguing and Corea eat dog nida.

Name: Anonymous 2013-03-26 14:32

>>1-21
pythonic dubz

Name: Anonymous 2013-03-26 14:37

>>23
I stole your dubs!

Name: Anonymous 2013-03-26 15:26

>>24
I STOLE YER DERBS.

Name: Anonymous 2013-03-26 15:33

>>21-22
What the fuck is a ``spic'' and why do you keep using what seems to be a derogatory racist term when referring to yourself?
I don't get it.
Are you somewhat confused of being a mix between noble and glorious amerindians, violent greedy colonizing half-semites spaniards, filthy jews slave traders and garbage niggers? Call yourself a fucking human and get over it.

Name: Anonymous 2013-03-26 15:49

>>26

A spic is something, which you put around your dick.

Name: Anonymous 2013-03-26 16:41

>>27
Shalom, Hymie!

Name: Anonymous 2013-03-26 16:42

>>28
But it is true. I put it around my dick. It feels good.

Name: Anonymous 2013-03-26 16:46

>>26
I call myself a spic (and a nigger) because they're short and kawaii words. Calling myself a Hispanic individual or an African-American individual would be gay.

Name: Anonymous 2013-03-26 16:48

>>30
Too bad that ``beaner'' is a Mexican-only word. It's funny, short and even cute as far as pejoratives go.

Sudaca will have to do.

Name: Anonymous 2013-03-26 17:07

>>30
Who is asking you to call yourself anything?

Name: Anonymous 2013-03-26 17:18

Oh, Danny boy, the JEWS, the JEWS are calling

Name: Anonymous 2013-03-26 17:26

>>30
As a Gay Anus Haxer, I am offended by these spics and niggers.

Name: Anonymous 2013-03-26 17:33

>>31
Sudaca doesn't sound as kawaii as spic.

Name: Anonymous 2013-03-26 18:04

Really, I can't see myself visiting a nigger-themed forum (say, a rap forum) and yelling "hello everybody I'm a white-ass, a cracker!!!"

Also I'm pretty sure nobody ever called you a spic here. We have many racisms, but we don't have that one.

Name: Anonymous 2013-03-26 18:15

As a non-humanities student, I don't get offended by words.

Name: Anonymous 2013-03-26 18:43

>>36
and that's racist.

Name: Anonymous 2013-03-26 18:44

/prog/ is not your personal debugger

Name: Anonymous 2013-03-26 19:15

>>38
Is it racism if I hate everyone equally?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List