1
2
my @name = ("heinz", "karl", "Peter", "Anne", "heinz", "Anne");
my @geb = ("20101920", "23011929", "02121915", "06041966","20101920", "07071977");
2014-01-21T16:06:39 kristianHallo
sag uns doch bitte im Vorfeld um welche Hausaufgabe es hier geht.
UNI / Kurs ?
Du musst nur ehrlich sein, dann klappt das schon.
Gruß Kristian
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
#! /usr/bin/env perl use strict; use warnings; sub remove_duplicates { my ( $nameR, $gebR ) = @_; die "Arrays are not same size.\n" if $#{$nameR} != $#{$gebR}; # identify duplicates and remember their indexes my %seen; my @idx = grep { $seen{$nameR->[$_].$gebR->[$_] }++ } 0 .. $#{$nameR}; # remove the identified elements for my $i ( @idx ) { splice @$nameR, $i, 1; splice @$gebR, $i, 1; } } my @name = ("heinz", "karl", "Peter", "Anne", "heinz", "Anne"); my @geb = ("20101920", "23011929", "02121915", "06041966","20101920", "07071977"); # keep in mind: this modifies the given arrays remove_duplicates( \@name, \@geb ); # check result printf "%8s ", $_ for @name; print "\n"; printf "%8s ", $_ for @geb; print "\n";
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/usr/bin/perl use strict; use warnings; my @name = ("heinz", "karl", "Peter", "Anne", "heinz", "Anne"); my @geb = ("20101920", "23011929", "02121915", "06041966","20101920", "07071977"); my %all; # Verschachtelter Hash für den ganzen Datenbestand for my $i (0..$#name) { $all{$name[$i]}->{$geb[$i]} .= "Rechnung Nr. $i "; } for my $nam (sort keys %all) { for my $geb (sort keys %{$all{$nam}}) { print "$nam, $geb: $all{$nam}->{$geb}\n"; } }
1
2
3
4
5
Anne, 06041966: Rechnung Nr. 3
Anne, 07071977: Rechnung Nr. 5
Peter, 02121915: Rechnung Nr. 2
heinz, 20101920: Rechnung Nr. 0 Rechnung Nr. 4
karl, 23011929: Rechnung Nr. 1
1 2 3 4 5
my @name = ("heinz", "karl", "Peter", "Anne", "heinz", "Anne"); my @geb = ("20101920", "23011929", "02121915", "06041966","20101920", "07071977"); my %d=map{"$name[$_]|$geb[$_]" => [$_,$name[$_],$geb[$_]]}(0..$#name); @name=(); @geb=(); map{push(@name,$_->[1]);push(@geb,$_->[2]);}sort{$a->[0] <=> $b->[0]}values(%d);
1 2 3
my @name = ("heinz", "karl", "Peter", "Anne", "heinz", "Anne"); my @geb = ("20101920", "23011929", "02121915", "06041966", "20101920", "07071977"); map{unshift(@name,$_->[1]);unshift(@geb,$_->[2]);}sort{$b->[0] <=> $a->[0]}values(%{{map{$name[0]."|".$geb[0] => [$_,shift(@name),shift(@geb)]}(0..$#name)}});
1 2 3 4 5 6
my @name = ("heinz", "karl", "Peter", "Anne", "heinz", "Anne"); my @geb = ("20101920", "23011929", "02121915", "06041966","20101920", "07071977"); my %hash = (); @hash{@name} = @geb; # hash slice print Dumper \%hash;
QuoteBei Anne ist das Geburtsdatum unterschiedlich.
2014-01-21T17:36:38 rostiDie in der Aufgabenstellung vorgelegte Datensammlung ist Schrott. Überlege Dir bereits VOR der Datenerhebung (das ist die Stelle, wo Daten anfallen) ein Verfahren, was konsistente Daten liefert.
QuoteWieso soll die Datensammlung Schrott sein? ...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/usr/bin/env python # coding: iso-8859-1 name = ["heinz", "karl", "Peter", "Anne", "heinz", "Anne"] geb = ["20101920", "23011929", "02121915", "06041966","20101920", "07071977"] name2 = [] geb2 = [] h = {} for i in range(len(name)): if not h.has_key(name[i]): h[name[i]] = [] h[name[i]].append(geb[i]) if h[name[i]].count(geb[i]) < 2: name2.append(name[i]) geb2.append(geb[i]) print name2 print geb2