Why does an element appear to have four children in Beautiful Soup? - beautifulsoup

When I call
for c in soup.contents:
c.name
I get:
html
But when I call
for c in soup.contents:
type(c)
I get:
<class 'bs4.element.Doctype'>
<class 'bs4.element.NavigableString'>
<class 'bs4.element.Tag'>
<class 'bs4.element.NavigableString'>
Why does there appear to be four distinct object with different types, when there is in reality only one child element, "html"?

Related

AttributeError: 'Styler' object has no attribute 'plot'

I worked on a database of skill workers in different courses and now I want to evaluate success in three different courses. After group by on databaase I get the below result:
Courses:
1 0.5882
2 0.2195
3 0.2857
I used style.format to change format value as percentage:
'style.format({'Courses': '{:,.2%}'.format})':
Courses:
1 58.82%
2 21.95%
3 28.57%
Now, for plot this values, I got the below error, how can I solve this problem?
AttributeError: 'Styler' object has no attribute 'plot'

Transpose array to rows using PIG latin

How to convert ARRY elements in BAG to multiple rows eg: below
My input:
tuple, ARRAY_ELEM
(32,{(1,emp,3271409712),(2,emp,3271409712)})
Output
(32,1,emp,3271409712)
(32,2,emp,3271409712)
You probably need to call FLATTEN twice.
Note, FLATTEN on a tuple just elevates each field in the tuple to a top-level field.
FLATTEN on bag produces a cross product of every record in the bag with all of the other expressions in GENERATE.
A = load 'test.txt' using PigStorage() as (a0:int, t1:(a1:int, b1 {(a3:int,a4:chararray,a5:chararray)}));
describe A;
B = FOREACH A GENERATE FLATTEN(t1);
describe B;
C = FOREACH B GENERATE a1, FLATTEN(b1);
describe C;
dump C;
Output
A: {a0: int,t1: (a1: int,b1: {(a3: int,a4: chararray,a5: chararray)})}
B: {t1::a1: int,t1::b1: {(a3: int,a4: chararray,a5: chararray)}}
C: {t1::a1: int,t1::b1::a3: int,t1::b1::a4: chararray,t1::b1::a5: chararray}
(32,1,emp,3271409712)
(32,2,emp,3271409712)

RxJava2 how to join 2 Single List into one list

I have 2 different data sources that I want to combine.
val source1: Single<List<Type1>> = Single.fromCallable({
api.getSource1()
})!!
val source2: Single<List<Type2>> = Single.fromCallable({
api.getSource2()
})!!
//PS.
class Type0()
class Type1 : Type0()
class Type2 : Type0()
I want to join 2 sources and get
Single<List<Type0>>
so I could do further processing of the data, I think I should use .zip method, but I am not sure how to do it correctly.
The zipWith operator works well here, as it lets you provide a BiFunction that describes how to combine the two Single instances (in this case, we just concatenate them with the plus operator):
val zipped: Single<List<Type0>> = source1.zipWith(source2, BiFunction { l1, l2 -> l1 + l2 })

PIG - Converting elements of bags into fields

I have a Pig query with the following output (one row)
(6,{(6,76,35,1565),(6,76,76,920),(6,35,76,906),(6,177,35,822),(6,268,35,720),(6,35,177,701),(6,35,268,694),(6,35,35,656),(6,85,85,611),(6,35,90,559)})
I would like to transform each element of my bag into a field, so
(6,(6,76,35,1565),(6,76,76,920),(6,35,76,906),(6,177,35,822),(6,268,35,720),(6,35,177,701),(6,35,268,694),(6,35,35,656),(6,85,85,611),(6,35,90,559))
where I can name every field with a different name : x1, x2, x3,....,
I tried flattening but that made one row for each element of the bag:
6,(6,76,35,1565)
6,(6,76,76,920)
6, (6,35,76,906)
And I want all the elements to remain in one single row.
Any ideas?
try the following links it may be helpfull
1.How to convert fields to rows in Pig?
2.write array from pig
You will have to use BagToTuple.Assuming you have a relation A with 2 fields.
B = FOREACH A GENERATE A.$0,FLATTEN(BagToTuple(A.$1));

Cocoa Mac app, bind NSTableColumn to an Entity

Mac app with Core Data:
I have 3 entities:
A <-->> B <<--> C, C has a BOOLEAN atribute.
Now I want do display, in a 2 Column Table, the name of A (1st column) and a boolean value (2nd column) which based on the boolean values from C.
For example:
An Object from type A (called a) owns 3 Objects from Type B (called b1, b2, b3).
Each of these 3 Objects owns 1 Object from Type C (called c1, c2, c3).
If the boolean Attribute of one of these Objects (c1, c2, c3) is TRUE, the boolean in the 2nd column have to be true.
I have tried something like that (with a custom ArrayController Class):
[NSTableColumn bind:#"value" toObject:self withKeyPath:#"arrangedObjects.b.c.#sum.boolValue" options:nil];
The ArrayController self is in Entity Name mode with Entity Name: A.
Are you sure #sum should be after c? There are 3 objects of type b for each a right? so, "b" is the collection in your case.
From the KVC Guide:
Simple Collection Operators
Simple collection operators operate on the properties to the right of
the operator in either an array or set.
And:
#sum
The #sum operator returns the sum of the values of the property
specified by the key path to the right of the operator. Each number is
converted to a double, the sum of the values is computed, and the
total is wrapped as an instance of NSNumber and returned.
Have you tried:
#"arrangedObjects.b.#sum.c.boolValue"