问:
How do I aggregate the values from two columns and create a new column from it?
How can I sum up the values in column "number" for each state and then create a new column from those values next to "number"?

So far I have this to aggregate:

```<code>out_state_total['df']=df.groupby('State')['out-of-state'].sum(axis=1)
</code>```

But for some reason I can't create a new column from those values...

```<code>example state  in-state  out-of-state final_state
red      NJ     3000     99           AL
blue     ND     43       500          AK
green    NY     8000     10           AZ
gray     NJ     94       20           AR
orange   DE     32       7
</code>```

答:
Use Transform

```<code>df[['in_state_total','out_state_total']]=df.groupby('state')['in-state', 'out-of-state'].transform('sum')

    example state   in-state    out-of-state    in_state_total  out_state_total
0   red     NJ      3000        99              3094            119
1   blue    ND      43          500             43              500
2   green   NY      8000        10              8000            10
3   gray    NJ      94          20              3094            119
4   orange  DE      32          7               32              7
</code>```

Body:
How can I sum up the values in column "number" for each state and then create a new column from those values next to "number"?

So far I have this to aggregate:

out_state_total['df']=df.groupby('State')['out-of-state'].sum(axis=1)

But for some reason I can't create a new column from those values...

example state  in-state  out-of-state final_state
red      NJ     3000     99           AL
blue     ND     43       500          AK
green    NY     8000     10           AZ
gray     NJ     94       20           AR
orange   DE     32       7

Body:
Use Transform

df[['in_state_total','out_state_total']]=df.groupby('state')['in-state', 'out-of-state'].transform('sum')

    example state   in-state    out-of-state    in_state_total  out_state_total
0   red     NJ      3000        99              3094            119
1   blue    ND      43          500             43              500
2   green   NY      8000        10              8000            10
3   gray    NJ      94          20              3094            119
4   orange  DE      32          7               32              7


来源: stackexchange

问:
Oracle to EDB Postgres Java embedded SQL issues
I'm working on a migration project to move from Oracle to EDB Postgres (including changing Java code that makes DB calls via JDBC, to make it work wth both Oracle and Postgres). EDB Postgres comes with an in-built PL/ Java layer that does some conversion of Oracle functions to their respective equivalents in Postgres. However, this isn't working in all cases.

We are using Oracle 11g and EDB Postgres 9.5

Some of the issues we've faced so far with postgres are:

```<code>org.postgresql.util.PSQLException: ERROR: date format not recognized (for format 'DD/MM/YYYY HH24:MI:SSxFF3)
org.postgresql.util.PSQLException: Bad value for type long (getClob and setClob don't work with postgres text columns)
org.postgresql.util.PSQLException: ERROR: syntax error at or near "NAME" (Any column alias named NAME fails during JDBC PreparedStatement execution)
org.postgresql.util.PSQLException: ERROR: syntax error at or near "TEMPLATE" (Any column alias named TEMPLATE fails during JDBC PreparedStatement execution)
</code>```

EDIT:
Java code is straight-forward. Snippets below include Java calls and table details:

Issue #1

```<code>create table table_name (TEMPLATE varchar2(10))
</code>```

Column Data types:

```<code>Oracle
TEMPLATE varchar2(10)
</code>```

Postgres

```<code>TEMPLATE character varying (10) (Postgres table was created by the EDB postgres migration toolkit)
</code>```

Issue in the below SQL is with the column alias TEMPLATE, works if I change the alias to say TEMPLATE1, TEMPLATE seems to be a keyword in Postgres.

```<code>sqlQuery = "SELECT A.TEMPLATE TEMPLATE FROM TABLE_NAME A";
preparedStatement = conn.prepareStatement(sqlQuery);
resultSet = preparedStatement.executeQuery();
//Works in Oracle, ERROR in postgres: syntax error at or near "TEMPLATE"
</code>```

Issue #2

```<code>create table table_name1 (date_col TIMESTAMP(6))
</code>```

Column Data types:

```<code>Oracle
Date_Col TIMESTAMP(6)
</code>```

Postgres

```<code>Date_Col timestamp without time zone (Postgres table was created by the EDB postgres migration toolkit)

sqlQuery = "Select TO_CHAR(DATE_COL,'DD/MM/YYYY HH24:MI:SSxFF3') from TABLE_NAME1";
preparedStatement = conn.prepareStatement(sqlQuery);
resultSet = preparedStatement.executeQuery();
//Works in Oracle, ERROR in postgres: date format not recognized
</code>```

While we have specific solutions to each of the issues listed above, suggestions/ recommendations to handle such differences in Java based on experiences of moving from Oracle to Postgres would be helpful. We would want to move to Java code that would work for both Postgres and Oracle (Ideally!) and would like to avoid if-else code to call Oracle vs Postgres specific SQLs.

答:
One possible solution I found for the NAME, TEMPLATE keyword errors is to quote the column alias, that way postgres does not treat NAME, TEMPLATE as keyword(s).

```<code>SELECT A.TEMPLATE TEMPLATE FROM TABLE_NAME A
org.postgresql.util.PSQLException: ERROR: syntax error at or near "TEMPLATE" (Any column alias named TEMPLATE fails during JDBC PreparedStatement execution)
</code>```

Change it to:

```<code>SELECT A.TEMPLATE "TEMPLATE" FROM TABLE_NAME A
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I'm working on a migration project to move from Oracle to EDB Postgres (including changing Java code that makes DB calls via JDBC, to make it work wth both Oracle and Postgres). EDB Postgres comes with an in-built PL/ Java layer that does some conversion of Oracle functions to their respective equivalents in Postgres. However, this isn't working in all cases.

We are using Oracle 11g and EDB Postgres 9.5

Some of the issues we've faced so far with postgres are:

org.postgresql.util.PSQLException: ERROR: date format not recognized (for format 'DD/MM/YYYY HH24:MI:SSxFF3)
org.postgresql.util.PSQLException: Bad value for type long (getClob and setClob don't work with postgres text columns)
org.postgresql.util.PSQLException: ERROR: syntax error at or near "NAME" (Any column alias named NAME fails during JDBC PreparedStatement execution)
org.postgresql.util.PSQLException: ERROR: syntax error at or near "TEMPLATE" (Any column alias named TEMPLATE fails during JDBC PreparedStatement execution)

EDIT:
Java code is straight-forward. Snippets below include Java calls and table details:

Issue #1

create table table_name (TEMPLATE varchar2(10))

Column Data types:

Oracle
TEMPLATE varchar2(10)

Postgres

TEMPLATE character varying (10) (Postgres table was created by the EDB postgres migration toolkit)

Issue in the below SQL is with the column alias TEMPLATE, works if I change the alias to say TEMPLATE1, TEMPLATE seems to be a keyword in Postgres.

sqlQuery = "SELECT A.TEMPLATE TEMPLATE FROM TABLE_NAME A";
preparedStatement = conn.prepareStatement(sqlQuery);
resultSet = preparedStatement.executeQuery();
//Works in Oracle, ERROR in postgres: syntax error at or near "TEMPLATE"

Issue #2

create table table_name1 (date_col TIMESTAMP(6))

Column Data types:

Oracle
Date_Col TIMESTAMP(6)

Postgres

Date_Col timestamp without time zone (Postgres table was created by the EDB postgres migration toolkit)

sqlQuery = "Select TO_CHAR(DATE_COL,'DD/MM/YYYY HH24:MI:SSxFF3') from TABLE_NAME1";
preparedStatement = conn.prepareStatement(sqlQuery);
resultSet = preparedStatement.executeQuery();
//Works in Oracle, ERROR in postgres: date format not recognized

While we have specific solutions to each of the issues listed above, suggestions/ recommendations to handle such differences in Java based on experiences of moving from Oracle to Postgres would be helpful. We would want to move to Java code that would work for both Postgres and Oracle (Ideally!) and would like to avoid if-else code to call Oracle vs Postgres specific SQLs.

Body:
One possible solution I found for the NAME, TEMPLATE keyword errors is to quote the column alias, that way postgres does not treat NAME, TEMPLATE as keyword(s).

SELECT A.TEMPLATE TEMPLATE FROM TABLE_NAME A
org.postgresql.util.PSQLException: ERROR: syntax error at or near "TEMPLATE" (Any column alias named TEMPLATE fails during JDBC PreparedStatement execution)

Change it to:

SELECT A.TEMPLATE "TEMPLATE" FROM TABLE_NAME A


问:
Passing data via intent in android
I have 5 activities, say activity A,B,C,D and E.

Each activity has two buttons yes & no,buttons have the data which I want to pass to activity E only.

I need to do following things:

--> When user press yes/no button of A_activity, the user move to B_activity but data passed to activity E via intent.
Similarly at activity B user press yes/no button, user will move to activity C but data passed to activity E and so on.

I have done lot of search but couldn't find solution is there any way to do this.

答:
You can indeed pass data back through an intent to an Activity's onActivityResult()

Activity E starting Activity A

```<code>final int RESULT_FOR_CLASS_DATA = 12; // pick a number to use
String returnedData;

Intent intent = new Intent(this, ActivityA.class);
startActivityForResult(intent, RESULT_FOR_CLASS_DATA);
</code>```

Example in A (started from E)

```<code>Intent data = new Intent();
data.putExtra("ReturnData", dataToReturn);
setResult(RESULT_OK, data);
finish(); // returning to Activity E
</code>```

Example in onActivityResult() of E

```<code>if (requestCode == RESULT_FOR_CLASS_DATA) {
    returnedData = data.getStringExtra("ReturnData"));
}
</code>```

There's a wide variety of ways to accomplish moving data around though so this is just one example.

To recommend an alternative, use Handler instead of this. Supposed that since the return Activity is paused, handler might require setting data in a separate class or global static variables, etc. and retrieved on Activity restart or something. So its possible to do with little to no code duplication in any class. Just retrieve and use. Whereas Intent requires code duplication in every class. It would also easily allow going from any Activity to any Activity like A->B->E->C instead of requiring E->A->E->B. Just something to think about.

Title: Passing data via intent in android

Body:
You can indeed pass data back through an intent to an Activity's onActivityResult()

Activity E starting Activity A

final int RESULT_FOR_CLASS_DATA = 12; // pick a number to use
String returnedData;

Intent intent = new Intent(this, ActivityA.class);
startActivityForResult(intent, RESULT_FOR_CLASS_DATA);

Example in A (started from E)

Intent data = new Intent();
data.putExtra("ReturnData", dataToReturn);
setResult(RESULT_OK, data);
finish(); // returning to Activity E

Example in onActivityResult() of E

if (requestCode == RESULT_FOR_CLASS_DATA) {
    returnedData = data.getStringExtra("ReturnData"));
}

There's a wide variety of ways to accomplish moving data around though so this is just one example.

To recommend an alternative, use Handler instead of this. Supposed that since the return Activity is paused, handler might require setting data in a separate class or global static variables, etc. and retrieved on Activity restart or something. So its possible to do with little to no code duplication in any class. Just retrieve and use. Whereas Intent requires code duplication in every class. It would also easily allow going from any Activity to any Activity like A->B->E->C instead of requiring E->A->E->B. Just something to think about.


问:
AttributeError: module 'matplotlib.pyplot' has no attribute 'xlable'
```<code>import matplotlib.pyplot as plt

squares = [1,4,9,16,25]
plt.plot(squares,linewidth=5)

plt.title('Square Number',fontsize=24)
plt.xlable('Value',fontsize=14)
plt.ylable('Square of Value',fontsize=14)

plt.tick_params(axis='both',lablesize=14)
plt.show()
</code>```

Is it because of the version of the problem?

答:
You can try like this   :

```<code>import matplotlib.pyplot as plt

squares = [1,4,9,16,25]
plt.plot(squares,linewidth=5)

plt.title('Square Number',fontsize=24)
plt.xlabel('Value',fontsize=14)
plt.ylabel('Square of Value',fontsize=14)

plt.tick_params(axis='both',labelsize=14)
plt.show()
</code>```

your question is and should be changed to，

xlable -> xlabel,

ylable -> ylabel,

lablesize -> labelsize, spell the label right.

Body:
import matplotlib.pyplot as plt

squares = [1,4,9,16,25]
plt.plot(squares,linewidth=5)

plt.title('Square Number',fontsize=24)
plt.xlable('Value',fontsize=14)
plt.ylable('Square of Value',fontsize=14)

plt.tick_params(axis='both',lablesize=14)
plt.show()

Is it because of the version of the problem?

Body:
You can try like this   :

import matplotlib.pyplot as plt

squares = [1,4,9,16,25]
plt.plot(squares,linewidth=5)

plt.title('Square Number',fontsize=24)
plt.xlabel('Value',fontsize=14)
plt.ylabel('Square of Value',fontsize=14)

plt.tick_params(axis='both',labelsize=14)
plt.show()

your question is and should be changed to，

xlable -> xlabel,

ylable -> ylabel,

lablesize -> labelsize, spell the label right.

ContentLicense: CC BY-SA 4.0


问:
PHP Laravel Blade @include pass data into WordPress query
I'm using Sage 9 WordPress starter theme.https://github.com/roots/sage

After include the template in Laravel Blade and pass some data.

```<code>@include ('partials.filter-archive', ['taxonomy' => 'project-type'])
</code>```

How could I use it in my template partials.filter-archive ??
{{ $taxonomy }} doesn't seem to work :(

```<code>@php
  $terms = get_terms(array(
    'taxonomy' => {{ $taxonomy }},
    'orderby' => 'menu_order',
  ));
  print_r($terms);
@endphp
</code>```

答:
try this once

```<code>@include ('partials.filter-archive', ['taxonomy' => "project-type"]);
</code>```

and try to do this {{ $taxonomy }} before calling wp function, and check if its getting printed

Body:
I'm using Sage 9 WordPress starter theme.https://github.com/roots/sage

After include the template in Laravel Blade and pass some data.

@include ('partials.filter-archive', ['taxonomy' => 'project-type'])

How could I use it in my template partials.filter-archive ??
{{ $taxonomy }} doesn't seem to work :(

@php
  $terms = get_terms(array(
    'taxonomy' => {{ $taxonomy }},
    'orderby' => 'menu_order',
  ));
  print_r($terms);
@endphp

Body:
try this once

@include ('partials.filter-archive', ['taxonomy' => "project-type"]);

and try to do this {{ $taxonomy }} before calling wp function, and check if its getting printed


问:
HTML is it possible to set second class inherit the main id?
Is it possible for me to set the second class to inherit the main class ID?

Codepen: https://codepen.io/jayvicious/pen/EXardz

.productholder {
  width: 50%;
  display: inline-block;
}

#content2p {
  padding-top: 19px;
  padding-bottom: 40px;
  margin-left: 6cm;
  width: auto;
}

.bookingFormHeader {
  display: inline-flex;
  background-color: lightgrey;
  width: 300px;
  border: 25px solid green;
  padding: 25px;
  margin: 25px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="content2p">

  <img class="productholder" src="http://via.placeholder.com/662x442.png">
  <p class="bookingFormHeader">Test Test</p>

</div></code>```

Explanation :-

I've set a container with the id content2p . Here i want to put two class side by side. The first class productholder is working fine. My only issue would be bookingFormHeader . It's indenting to the bottom, i want to make it same line as below example output:

The booking is actually a form with border box :

I've tried many ways by changing the display to the following :-

inline-block
 flex
 table
 inline-table

Yet i've got no luck , is there any element I'm missing??
Appreciate in advance.

答:
Is this what you are after? Please adjust margins and width to you liking.

#content2p {
  padding-top: 19px;
  padding-bottom: 40px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.bookingFormHeader {
  background-color: lightgrey;
  width: 100px;
  border: 25px solid green;
  padding: 25px;
  margin: 25px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="content2p">

  <img class="productholder" src="http://www.placehold.it/80">
  <p class="bookingFormHeader">Test Test</p>

</div></code>```

Body:
Is it possible for me to set the second class to inherit the main class ID?

Codepen: https://codepen.io/jayvicious/pen/EXardz

.productholder {
  width: 50%;
  display: inline-block;
}

#content2p {
  padding-top: 19px;
  padding-bottom: 40px;
  margin-left: 6cm;
  width: auto;
}

.bookingFormHeader {
  display: inline-flex;
  background-color: lightgrey;
  width: 300px;
  border: 25px solid green;
  padding: 25px;
  margin: 25px;
}

Test Test

Explanation :-

I've set a container with the id content2p . Here i want to put two class side by side. The first class productholder is working fine. My only issue would be bookingFormHeader . It's indenting to the bottom, i want to make it same line as below example output:

The booking is actually a form with border box :

I've tried many ways by changing the display to the following :-

inline-block
 flex
 table
 inline-table

Yet i've got no luck , is there any element I'm missing??
Appreciate in advance.

Body:
Is this what you are after? Please adjust margins and width to you liking.

#content2p {
  padding-top: 19px;
  padding-bottom: 40px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.bookingFormHeader {
  background-color: lightgrey;
  width: 100px;
  border: 25px solid green;
  padding: 25px;
  margin: 25px;
}

<div id="content2p">

  <img class="productholder" src="http://www.placehold.it/80">
  <p class="bookingFormHeader">Test Test</p>

</div>


问:
how to align progress bar in webview Android?
I wrote simple web view application in android but the progress bar is showing the very top of the application click
here to view the image.
actually, I want to do like this click here

This is my
Main activity

```<code>public class MainActivity extends AppCompatActivity implements MyWebChromeClient.ProgressListener {

WebView wv;
private ProgressBar mProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    wv=(WebView) findViewById(R.id.webview);
    WebSettings settings = wv.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.getLoadsImagesAutomatically();
    settings.getBuiltInZoomControls();
    settings.setSaveFormData(true);
    settings.setEnableSmoothTransition(true);
    settings.setNeedInitialFocus(true);
    settings.setSavePassword(true);
    settings.setDomStorageEnabled(true);
    settings.setPluginState(WebSettings.PluginState.ON);
    // add progress bar
    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    wv.loadUrl("https://www.w3schools.com/");
    wv.setWebChromeClient(new MyWebChromeClient(this));
    wv.setWebViewClient(new WebViewClient(){
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            mProgressBar.setVisibility(View.VISIBLE);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            mProgressBar.setVisibility(View.GONE);

        }
    });
}

@Override
public void onBackPressed() {
    if(wv.canGoBack()){

        wv.goBack();
    }
    else{
        super.onBackPressed();
    }
}

@Override
public void onUpdateProgress(int progressValue) {
    mProgressBar.setProgress(progressValue);
    if (progressValue == 100) {
        mProgressBar.setVisibility(View.INVISIBLE);
    }
}}
</code>```

In this layout i added webview and progressbar.

activity_main.xml

```<code> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.johnson.apple.MainActivity">
    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />
    <ProgressBar
        android:id="@+id/progressBar"
        android:minHeight="2dip"
        android:maxHeight="2dip"
        android:progressDrawable="@drawable/bg_progress_bar_webview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        style="@android:style/Widget.ProgressBar.Horizontal" />
</RelativeLayout>
</code>```

Hope anyone can help me
Thnaks in advance

答:
I did little hack on this the answer is modifying the activity_xml

```<code><?xml version="1.0" encoding="utf-8"?><android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.app.superdeveloper.weblc.learncoding.MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />
    <ProgressBar
        android:id="@+id/progressBar"
        android:minHeight="2dip"
        android:maxHeight="2dip"
        android:progressDrawable="@drawable/bg_progress_bar_webview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        style="@android:style/Widget.ProgressBar.Horizontal" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    app:srcCompat="@android:drawable/ic_dialog_email" /></android.support.design.widget.CoordinatorLayout>
</code>```

Now it works

Body:
I wrote simple web view application in android but the progress bar is showing the very top of the application click
here to view the image.
actually, I want to do like this click here

This is my
Main activity

public class MainActivity extends AppCompatActivity implements MyWebChromeClient.ProgressListener {

WebView wv;
private ProgressBar mProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    wv=(WebView) findViewById(R.id.webview);
    WebSettings settings = wv.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.getLoadsImagesAutomatically();
    settings.getBuiltInZoomControls();
    settings.setSaveFormData(true);
    settings.setEnableSmoothTransition(true);
    settings.setNeedInitialFocus(true);
    settings.setSavePassword(true);
    settings.setDomStorageEnabled(true);
    settings.setPluginState(WebSettings.PluginState.ON);
    // add progress bar
    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    wv.loadUrl("https://www.w3schools.com/");
    wv.setWebChromeClient(new MyWebChromeClient(this));
    wv.setWebViewClient(new WebViewClient(){
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            mProgressBar.setVisibility(View.VISIBLE);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            mProgressBar.setVisibility(View.GONE);

        }
    });
}

@Override
public void onBackPressed() {
    if(wv.canGoBack()){

        wv.goBack();
    }
    else{
        super.onBackPressed();
    }
}

@Override
public void onUpdateProgress(int progressValue) {
    mProgressBar.setProgress(progressValue);
    if (progressValue == 100) {
        mProgressBar.setVisibility(View.INVISIBLE);
    }
}}

In this layout i added webview and progressbar.

activity_main.xml

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.johnson.apple.MainActivity">
    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />
    <ProgressBar
        android:id="@+id/progressBar"
        android:minHeight="2dip"
        android:maxHeight="2dip"
        android:progressDrawable="@drawable/bg_progress_bar_webview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        style="@android:style/Widget.ProgressBar.Horizontal" />
</RelativeLayout>

Hope anyone can help me
Thnaks in advance

Body:
I did little hack on this the answer is modifying the activity_xml

<?xml version="1.0" encoding="utf-8"?><android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.app.superdeveloper.weblc.learncoding.MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />
    <ProgressBar
        android:id="@+id/progressBar"
        android:minHeight="2dip"
        android:maxHeight="2dip"
        android:progressDrawable="@drawable/bg_progress_bar_webview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        style="@android:style/Widget.ProgressBar.Horizontal" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    app:srcCompat="@android:drawable/ic_dialog_email" /></android.support.design.widget.CoordinatorLayout>

Now it works


问:
React.JS simple component not rendering nested html tag
This is a simple piece of code. I am trying to get my first component to run and I followed the tutorial and this is their code for creating the component.

It works in that it does inject the first  into the html document but the  is missing.

For some reason it worked perfectly for the instructor in the video, as you can see here: https://youtu.be/G40iHC-h0c0?t=392

```<code>import React from "react";
import { render } from "react-dom";

class basicDiv extends React.Component {
    render(){
        return(
            <div>
                <h1>Hi my friend</h1>
            </div>
        );
    }
}

render(<basicDiv/>, window.document.querySelector(".componentPlaceHolder"));
</code>```

here is the index.html file:

```<code><!doctype html>

<html>

<head>

</head>
<body>
    <div class="componentPlaceHolder" style="border:1px solid black;min-height:100px;">

    </div>

    <script src="/app/bundle.js"></script>
</body>

</html>
</code>```

答:
React component class has to be capitalised. Change that and your code will work. See this doc for more details on JSX.

class BasicDiv extends React.Component {
    render(){
        return(

Hi my friend

        );
    }
}

ReactDOM.render(<BasicDiv/>, window.document.querySelector(".componentPlaceHolder"));```
<pre class="snippet-code-html lang-html prettyprint-override"><code><!doctype html>

<html>

<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>

</head>
<body>
    <h2>This is a Skeleton React Build</h2>
    <p>It uses babel to convert ES6 code to ES5</p>
    <p>This is a good place to start building your app. This is a blank canvas.</p>

    <h2>Below is where my first component will be injected</h2>
    <p>If you see anything in the box below... it works!</p>
    <div class="componentPlaceHolder" style="border:1px solid black;min-height:100px;">

    </div>

    <script src="/app/bundle.js"></script>
</body>

</html></code>```

Body:
This is a simple piece of code. I am trying to get my first component to run and I followed the tutorial and this is their code for creating the component.

It works in that it does inject the first  into the html document but the  is missing.

For some reason it worked perfectly for the instructor in the video, as you can see here: https://youtu.be/G40iHC-h0c0?t=392

import React from "react";
import { render } from "react-dom";

class basicDiv extends React.Component {
    render(){
        return(

Hi my friend

        );
    }
}

render(<basicDiv/>, window.document.querySelector(".componentPlaceHolder"));

here is the index.html file:

<!doctype html>

Body:
React component class has to be capitalised. Change that and your code will work. See this doc for more details on JSX.

class BasicDiv extends React.Component {
    render(){
        return(
            <div>
                <h1>Hi my friend</h1>
            </div>
        );
    }
}

ReactDOM.render(<BasicDiv/>, window.document.querySelector(".componentPlaceHolder"));

<!doctype html>

<html>

<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>

</head>
<body>
    <h2>This is a Skeleton React Build</h2>
    <p>It uses babel to convert ES6 code to ES5</p>
    <p>This is a good place to start building your app. This is a blank canvas.</p>

    <h2>Below is where my first component will be injected</h2>
    <p>If you see anything in the box below... it works!</p>
    <div class="componentPlaceHolder" style="border:1px solid black;min-height:100px;">

    </div>

    <script src="/app/bundle.js"></script>
</body>

</html>


问:
Create arrays out of arrays javascript
I have these three arrays:

```<code>var arr1 = [a1, b1, c1], arr2 = [a2, b2, c2], arr3 = [a3, b3, c3];
</code>```

How can I combine these arrays so that I can create arrays like the series of arrays in the bottom using jQuery/javascript?

```<code>array1 = [a1, a2, a3]
array2 = [a1, a2, b3]
array3 = [a1, a2, c3]
array4 = [a1, b2, a3]
array5 = [a1, b2, b3]
array6 = [a1, b2, c3]
array7 = [a1, c2, a3]
array8 = [a1, c2, b3]
array9 = [a1, c2, c3]

array10 = [b1, a2, a3]
array11 = [b1, a2, b3]
array12 = [b1, a2, c3]
array13 = [b1, b2, a3]
array14 = [b1, b2, b3]
array15 = [b1, b2, c3]
array16 = [b1, c2, a3]
array17 = [b1, c2, b3]
array18 = [b1, c2, c3]

array19 = [c1, a2, a3]
array20 = [c1, a2, b3]
array21 = [c1, a2, c3]
array22 = [c1, b2, a3]
array23 = [c1, b2, b3]
array24 = [c1, b2, c3]
array25 = [c1, c2, a3]
array26 = [c1, c2, b3]
array27 = [c1, c2, c3]
</code>```

答:
3 nested loops should be all you need...

var arr1 = ['a1', 'b1', 'c1'], arr2 = ['a2', 'b2', 'c2'], arr3 = ['a3', 'b3', 'c3']

var megaArray = []
for (let i = 0, l = arr1.length; i < l; i++) {
  for (let j = 0, m = arr2.length; j < m; j++) {
    for (let k = 0, n = arr3.length; k < n; k++) {
      megaArray.push([arr1[i], arr2[j], arr3[k]])
    }
  }
}
console.info(megaArray)```

Title: Create arrays out of arrays javascript

Body:
I have these three arrays:

var arr1 = [a1, b1, c1], arr2 = [a2, b2, c2], arr3 = [a3, b3, c3];

How can I combine these arrays so that I can create arrays like the series of arrays in the bottom using jQuery/javascript?

array1 = [a1, a2, a3]
array2 = [a1, a2, b3]
array3 = [a1, a2, c3]
array4 = [a1, b2, a3]
array5 = [a1, b2, b3]
array6 = [a1, b2, c3]
array7 = [a1, c2, a3]
array8 = [a1, c2, b3]
array9 = [a1, c2, c3]

array10 = [b1, a2, a3]
array11 = [b1, a2, b3]
array12 = [b1, a2, c3]
array13 = [b1, b2, a3]
array14 = [b1, b2, b3]
array15 = [b1, b2, c3]
array16 = [b1, c2, a3]
array17 = [b1, c2, b3]
array18 = [b1, c2, c3]

array19 = [c1, a2, a3]
array20 = [c1, a2, b3]
array21 = [c1, a2, c3]
array22 = [c1, b2, a3]
array23 = [c1, b2, b3]
array24 = [c1, b2, c3]
array25 = [c1, c2, a3]
array26 = [c1, c2, b3]
array27 = [c1, c2, c3]


问:
Git adding file having space in name
I am trying to update my file, but I was unable to do so because of file name contains two words

```<code>$ git add 00162808_LirajMaharjan_CP_Design/Class diagram.mdj
</code>```

Error:

```<code>fatal: pathspec '00162808_LirajMaharjan_CP_Design/Class' did not match any files
</code>```

Can I add a file like 'Class diagram/mdj' with spaces in the name?

答:
Either escape the space with a backslash:

```<code>git add 00162808_LirajMaharjan_CP_Design/Class\ diagram.mdj
</code>```

Or quote the filename:

```<code>git add "00162808_LirajMaharjan_CP_Design/Class diagram.mdj"
</code>```

Single quotes work too:

```<code>git add '00162808_LirajMaharjan_CP_Design/Class diagram.mdj'
</code>```

Title: Git adding file having space in name

Body:
I am trying to update my file, but I was unable to do so because of file name contains two words

$ git add 00162808_LirajMaharjan_CP_Design/Class diagram.mdj

Error:

fatal: pathspec '00162808_LirajMaharjan_CP_Design/Class' did not match any files

Can I add a file like 'Class diagram/mdj' with spaces in the name?

Body:
Either escape the space with a backslash:

git add 00162808_LirajMaharjan_CP_Design/Class\ diagram.mdj

Or quote the filename:

git add "00162808_LirajMaharjan_CP_Design/Class diagram.mdj"

Single quotes work too:

git add '00162808_LirajMaharjan_CP_Design/Class diagram.mdj'


问:
How to ease nested looping?
I find myself looping over vectors of vectors a lot:

```<code>std::vector<std::vector<int> > foo;

for(unsigned int i=0; i != foo.size(); ++i) {
 for(unsigned int j=0; j != foo[i].size(); ++j) {
  // use foo[i][j]
 }
}
</code>```

I don't have a good minimal example why the "data" is represented best by a vector of vectors of int but let's don't doubt it here.

What do you suggest to simplify the looping? I could think of a function that implements the explicit looping and takes a pointer to a function for the body.

How to "generate" nested for-loops in case of more levels?

Are there languages that have "built-in" support for "nested looping"?

Thanks in advance,

Somebody

答:
There's no 'built-in' support for vector looping, but if done right, a smart compiler may optimize your for loops into code, which may make use of advanced CPU features, which may improve performance.

Generally speaking, there's nothing wrong with nested loops. But more often than not, when you have a nested loop, that code may be optimized to run faster. But this depends heavily on the code inside the loop, i.e. on the thing you're trying to do with the data in the vectors.

As pointed out by others, using iterators would improve your code in terms of compliance with C++ best practices. It will not improve performance, but it will improve type safety and compiler may be able to point out to you about mistakes that neither you, nor compiler may not have noticed otherwise.

If the thing you're doing inside the loops is very simple -- say, incrementing a value if it satisfies a condition, then standard C++ algorithms, like std::for_each, and predicates may be used to make the code more concise and readable.

But don't get carried away by these things, keep it simple. ;)

ContentLicense: CC BY-SA 2.5

Title: How to ease nested looping?

Body:
I find myself looping over vectors of vectors a lot:

std::vector<std::vector<int> > foo;

for(unsigned int i=0; i != foo.size(); ++i) {
 for(unsigned int j=0; j != foo[i].size(); ++j) {
  // use foo[i][j]
 }
}

I don't have a good minimal example why the "data" is represented best by a vector of vectors of int but let's don't doubt it here.

What do you suggest to simplify the looping? I could think of a function that implements the explicit looping and takes a pointer to a function for the body.

How to "generate" nested for-loops in case of more levels?

Are there languages that have "built-in" support for "nested looping"?

Thanks in advance,

Somebody


问:
How to select only one child in a list of classes
I am using a series of submit buttons for a navigation menu (the submit value will be the navigation method throughout the site).  I have created a dropdown menu with a flyout from the dropdowns.  However, I cannot figure out how to isolate only the hovered element in the dropdown to show it's flyout.  All dropdown items either show all submenus or none.  I have tried using the > and + child selectors in different areas.  Can anyone please help?

My CSS:

```<code>/* Dropdown Button */
.ddb-container {
width: 100%;
    overflow: hidden;
    background-color: #faebca;
    font-family: Arial;
    margin-top: 75px;
    padding-left: 150px;
    z-index: 1;
    border-top: 3px black solid;
    border-bottom: 3px black solid;
    border-left: none;
    border-right: none;
}

.ddb-container button {
    margin: 0;
    padding: 0;
    float: left;
    font-size: 14px;
    border: none;
    color: #000000;
    text-align: center;
    padding: 5px 10px;
    text-decoration: none;
    font-weight: bold;
    background-color: transparent;
}

.ddb-container button:hover {
    background-color: #dbcfa4;
}

.ddb-dropdown {
    float: left;
    overflow: hidden;
    font-size: 14px;
    font-weight: bold;
}

.ddb-dropdown .dropbtn {
    border: none;
    outline: none;
    color: #000000;
    padding: 5px 10px;
    background-color: transparent;
}

.ddb-dropdown .dropbtn:hover {
    background-color: #dbcfa4;
}

.ddb-dropdown .dropdown-level1 {
    display: none;
    position: absolute;
    background-color: #faebca;
    min-width: 160px;
    box-shadow: 0px 8px 12px 0px rgba(0,0,0,0.2);
    z-index: 1;
}

.ddb-dropdown:hover .dropdown-level1 {
    display: block;
}

.ddb-dropdown .dropdown-level1 .dropdown-level2 {
    display: none;
    position: absolute;
    background-color: #faebca;
    min-width: 160px;
    margin-left: 160px;
    box-shadow: 0px 8px 12px 0px rgba(0,0,0,0.2);
    z-index: 2;
}

.ddb-dropdown  .dropdown-level1:hover  .dropdown-level2 {
    display: block;
}
</code>```

HTML:

```<code><div class='ddb-container'>
<button type='submit' name='submit' value='0'>Home</button>
<div class='ddb-dropdown'>
    <div class='dropbtn'>Sales</div>
        <div class='dropdown-level1'><button type='submit' name='submit' value='#1'>Link 1</button><br /><br />
        <button type='button'>Link 2 ></button><br />
            <div class='dropdown-level2'>
            <button type='submit' name='submit' value='#1'>Sublink 1</button><br />
            <button type='submit' name='submit' value='#2'>Sublink 2</button><br />
            <button type='submit' name='submit' value='#3'>Sublink 3</button><br /><br />
            </div><br />
        <button type='submit' name='submit' value='#3'>Link 3</button><br /><br />
        <button type='submit' name='submit' value='#4'>Link 4</button><br /><br />
        <button type='button'>Link 5 ></button><br />
            <div class='dropdown-level2'>
            <button type='submit' name='submit' value='#1'>Sublink 1</button><br />
            <button type='submit' name='submit' value='#2'>Sublink 2</button><br />
            <button type='submit' name='submit' value='#3'>Sublink 3</button><br /><br />
            </div><br /><button type='submit' name='submit' value='#6'>Link 6</button><br /><br />
        </div>
</div>

<div class='ddb-dropdown'>
    <div class='dropbtn'>Purchasing</div>
</div>
<div class='ddb-dropdown'>
    <div class='dropbtn'>Inventory</div>
</div>
<div class='ddb-dropdown'>
    <div class='dropbtn'>Accounting</div>
</div>
<div class='ddb-dropdown'>
    <div class='dropbtn'>Documents</div>
</div>
<div class='ddb-dropdown'>
    <div class='dropbtn'>Tools</div>
        <div class='dropdown-level1'>
            <button type='submit' name='submit' value='#1'>Tools Link 1</button><br /><br />
            <button type='submit' name='submit' value='#2'>Tools Link 2</button><br /><br />
            <button type='submit' name='submit' value='#3'>Tools Link 3</button><br /><br />
            <button type='button'>Tools Link 4 ></button><br />
                <div class='dropdown-level2'>
                    <button type='submit' name='submit' value='#1'>Sublink 1</button><br />
                    <button type='submit' name='submit' value='#2'>Sublink 2</button><br />
                    <button type='submit' name='submit' value='#3'>Sublink 3</button><br /><br />
                </div><br />
            <button type='submit' name='submit' value='#5'>Tools Link 5</button><br /><br />
            <button type='submit' name='submit' value='#6'>Tools Link 6</button><br /><br />
        </div>
    </div>
<div class='ddb-dropdown'>
    <div class='dropbtn'>Employees</div>
</div>
<div class='ddb-dropdown'>
    <div class='dropbtn'>Administration</div>
</div>
</code>```

答:
With the HTML you currently have you can't get what you want with pure CSS. You would need javascript. Refactoring your HTML we can do this with CSS.

While it is not necessary to replace your buttons with a, it makes more sense to use links for navigation, make sure to use the correct url in the href attributes.

We could have achieved the hover effect by removing the br tags and using the adjacent sibling selector (+) but when hovering over the sub-menus the previous sibling would lose the hover and the sub-menu would disappear.

By creating a hierarchy we can keep the sub-menus active as while they are receiving a hover, so is their parent. Nested lists are a common way of marking up this hierarchy.

The following is a truncated version to get you on your way.

/*Basic List  Reset*/

ul.ddb-container,
ul.ddb-container ul {
  padding: 0;
  list-style: none;
}

/*Basic Link Reset*/

ul.ddb-container a {
  text-decoration: none;
}

ul.ddb-container a:link,
ul.ddb-container a:visited {
  color: #000;
}

/*Dropdown Magic*/

.ddb-container  ul {
  display: none;
}

.ddb-container {
  width: 100%;
  overflow: visible;
  background-color: #faebca;
  font-family: Arial;
  margin-top: 75px;
  padding-left: 150px;
  z-index: 1;
  border-top: 3px black solid;
  border-bottom: 3px black solid;
  border-left: none;
  border-right: none;
}

.ddb-container > li {
  margin: 0;
  padding: 0;
  display:inline-block;
  font-size: 14px;
  border: none;
  color: #000000;
  text-align: center;
  padding: 5px 10px;
  text-decoration: none;
  font-weight: bold;
  background-color: transparent;
  position:relative;
  overflow:visible;
}

.ddb-container li:hover {
  background-color: #dbcfa4;
}

.ddb-dropdown .dropdown-level1 {
  position: absolute;
  background-color: #faebca;
  min-width: 160px;
  box-shadow: 0px 8px 12px 0px rgba(0, 0, 0, 0.2);
  z-index: 1;
  text-align:left;
  top:26px;
  left: 0;
}

.ddb-dropdown .dropdown-level1 .dropdown-level2 {
  position: absolute;
  background-color: #faebca;
  min-width: 160px;
  margin-left: 160px;
  box-shadow: 0px 8px 12px 0px rgba(0, 0, 0, 0.2);
  z-index: 2;
}

.ddb-dropdown ul > li {
padding: 1em 0;
}

.ddb-container  li:hover > ul {
  display:block;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><ul class='ddb-container'>
  <li>
    Home
  </li>
  <li class='ddb-dropdown'>
    Sales
    <ul class="dropdown-level1">
      <li>Link 1</li>
      <li>Link 2 >
        <ul class='dropdown-level2'>
          <li>Link2 Sublink 1</li>
          <li>Link2 Sublink 2</li>
          <li>Link2 Sublink 3</li>
        </ul>
      </li>
      <li>Link 3</li>
      <li>Link 4</li>
      <li>Link 5 >
        <ul class='dropdown-level2'>
          <li>Link5 Sublink 1</li>
          <li>Link5 Sublink 2</li>
          <li>Link5 Sublink 3</li>
        </ul>
      </li>
      <li>Link 6</li>
    </ul>
  </li>
  <li>Purchasing</li>
</ul></code>```

Body:
I am using a series of submit buttons for a navigation menu (the submit value will be the navigation method throughout the site).  I have created a dropdown menu with a flyout from the dropdowns.  However, I cannot figure out how to isolate only the hovered element in the dropdown to show it's flyout.  All dropdown items either show all submenus or none.  I have tried using the > and + child selectors in different areas.  Can anyone please help?

My CSS:

/* Dropdown Button */
.ddb-container {
width: 100%;
    overflow: hidden;
    background-color: #faebca;
    font-family: Arial;
    margin-top: 75px;
    padding-left: 150px;
    z-index: 1;
    border-top: 3px black solid;
    border-bottom: 3px black solid;
    border-left: none;
    border-right: none;
}

.ddb-container button {
    margin: 0;
    padding: 0;
    float: left;
    font-size: 14px;
    border: none;
    color: #000000;
    text-align: center;
    padding: 5px 10px;
    text-decoration: none;
    font-weight: bold;
    background-color: transparent;
}

.ddb-container button:hover {
    background-color: #dbcfa4;
}

.ddb-dropdown {
    float: left;
    overflow: hidden;
    font-size: 14px;
    font-weight: bold;
}

.ddb-dropdown .dropbtn {
    border: none;
    outline: none;
    color: #000000;
    padding: 5px 10px;
    background-color: transparent;
}

.ddb-dropdown .dropbtn:hover {
    background-color: #dbcfa4;
}

.ddb-dropdown .dropdown-level1 {
    display: none;
    position: absolute;
    background-color: #faebca;
    min-width: 160px;
    box-shadow: 0px 8px 12px 0px rgba(0,0,0,0.2);
    z-index: 1;
}

.ddb-dropdown:hover .dropdown-level1 {
    display: block;
}

.ddb-dropdown .dropdown-level1 .dropdown-level2 {
    display: none;
    position: absolute;
    background-color: #faebca;
    min-width: 160px;
    margin-left: 160px;
    box-shadow: 0px 8px 12px 0px rgba(0,0,0,0.2);
    z-index: 2;
}

.ddb-dropdown  .dropdown-level1:hover  .dropdown-level2 {
    display: block;
}

HTML:

<button type='submit' name='submit' value='0'>Home</button>

Sales

<button type='submit' name='submit' value='#1'>Link 1</button>

        <button type='button'>Link 2 ></button>

            <button type='submit' name='submit' value='#1'>Sublink 1</button>

            <button type='submit' name='submit' value='#2'>Sublink 2</button>

            <button type='submit' name='submit' value='#3'>Sublink 3</button>

        <button type='submit' name='submit' value='#3'>Link 3</button>

        <button type='submit' name='submit' value='#4'>Link 4</button>

        <button type='button'>Link 5 ></button>

            <button type='submit' name='submit' value='#1'>Sublink 1</button>

            <button type='submit' name='submit' value='#2'>Sublink 2</button>

            <button type='submit' name='submit' value='#3'>Sublink 3</button>

<button type='submit' name='submit' value='#6'>Link 6</button>

Purchasing

Inventory

Accounting

Documents

Tools

            <button type='submit' name='submit' value='#1'>Tools Link 1</button>

            <button type='submit' name='submit' value='#2'>Tools Link 2</button>

            <button type='submit' name='submit' value='#3'>Tools Link 3</button>

            <button type='button'>Tools Link 4 ></button>

                    <button type='submit' name='submit' value='#1'>Sublink 1</button>

                    <button type='submit' name='submit' value='#2'>Sublink 2</button>

                    <button type='submit' name='submit' value='#3'>Sublink 3</button>

            <button type='submit' name='submit' value='#5'>Tools Link 5</button>

            <button type='submit' name='submit' value='#6'>Tools Link 6</button>

Employees

Administration

Body:
With the HTML you currently have you can't get what you want with pure CSS. You would need javascript. Refactoring your HTML we can do this with CSS.

While it is not necessary to replace your buttons with a, it makes more sense to use links for navigation, make sure to use the correct url in the href attributes.

We could have achieved the hover effect by removing the br tags and using the adjacent sibling selector (+) but when hovering over the sub-menus the previous sibling would lose the hover and the sub-menu would disappear.

By creating a hierarchy we can keep the sub-menus active as while they are receiving a hover, so is their parent. Nested lists are a common way of marking up this hierarchy.

The following is a truncated version to get you on your way.

/*Basic List  Reset*/

ul.ddb-container,
ul.ddb-container ul {
  padding: 0;
  list-style: none;
}

/*Basic Link Reset*/

ul.ddb-container a {
  text-decoration: none;
}

ul.ddb-container a:link,
ul.ddb-container a:visited {
  color: #000;
}

/*Dropdown Magic*/

.ddb-container  ul {
  display: none;
}

.ddb-container {
  width: 100%;
  overflow: visible;
  background-color: #faebca;
  font-family: Arial;
  margin-top: 75px;
  padding-left: 150px;
  z-index: 1;
  border-top: 3px black solid;
  border-bottom: 3px black solid;
  border-left: none;
  border-right: none;
}

.ddb-container > li {
  margin: 0;
  padding: 0;
  display:inline-block;
  font-size: 14px;
  border: none;
  color: #000000;
  text-align: center;
  padding: 5px 10px;
  text-decoration: none;
  font-weight: bold;
  background-color: transparent;
  position:relative;
  overflow:visible;
}

.ddb-container li:hover {
  background-color: #dbcfa4;
}

.ddb-dropdown .dropdown-level1 {
  position: absolute;
  background-color: #faebca;
  min-width: 160px;
  box-shadow: 0px 8px 12px 0px rgba(0, 0, 0, 0.2);
  z-index: 1;
  text-align:left;
  top:26px;
  left: 0;
}

.ddb-dropdown .dropdown-level1 .dropdown-level2 {
  position: absolute;
  background-color: #faebca;
  min-width: 160px;
  margin-left: 160px;
  box-shadow: 0px 8px 12px 0px rgba(0, 0, 0, 0.2);
  z-index: 2;
}

.ddb-dropdown ul > li {
padding: 1em 0;
}

.ddb-container  li:hover > ul {
  display:block;
}

<ul class='ddb-container'>
  <li>
    <a href="#">Home</a>
  </li>
  <li class='ddb-dropdown'>
    <a href="#">Sales</a>
    <ul class="dropdown-level1">
      <li><a href="#">Link 1</a></li>
      <li><a href="#">Link 2 ></a>
        <ul class='dropdown-level2'>
          <li><a href="#">Link2 Sublink 1</a></li>
          <li><a href="#">Link2 Sublink 2</a></li>
          <li><a href="#">Link2 Sublink 3</a></li>
        </ul>
      </li>
      <li><a href="#">Link 3</a></li>
      <li><a href="#">Link 4</a></li>
      <li><a href="#">Link 5 ></a>
        <ul class='dropdown-level2'>
          <li><a href="#">Link5 Sublink 1</a></li>
          <li><a href="#">Link5 Sublink 2</a></li>
          <li><a href="#">Link5 Sublink 3</a></li>
        </ul>
      </li>
      <li><a href="#">Link 6</a></li>
    </ul>
  </li>
  <li><a href="#">Purchasing</a></li>
</ul>


问:
Python : Comparing file name with folder name in same directory
I have a folder with lot of zip files and the extracted folders for the same.
The folder has become so much clustered .

Is there any way to compare the zipped files name with the EXTRACTED folders name in the same directory ?

i want to delete the EXTRACTED folders if they have a .zip file in the same directory.

答:
Hope it help</p>

```<code>import os
import shutil

for file in os.listdir(path_to_dir):
    if os.path.isdir(file + ".zip"):
        shutil.rmtree(file)
</code>```

Body:
Hope it help

import os
import shutil

for file in os.listdir(path_to_dir):
    if os.path.isdir(file + ".zip"):
        shutil.rmtree(file)


问:
Send mock response based on request header content in soapui
I have two mock responses eg: A, B

I want to write condition for mock responses like

if request header(ex:"myheader") value is "a" then send Mock response A

if request header(ex:"myheader") value is "b" then send Mock response B

答:
Yes, it is very much possible to mock using soapui.

Let us assume that when a rest service is invoked, it is possible to have different responses based on user's request header Content-Type value.

xmlResponse

jsonResponse

faultResponse

So, add above three responses to the mock service. And user SCRIPT as dispatcher.

Mock Service Script as follows:

```<code>def responseType = mockRequest.request.getHeader('Content-Type')
if (!responseType) {
    return "faultResponse"
}
if ('application/json' == responseType.toLowerCase() || 'json' == responseType.toLowerCase()) {
    return "jsonResponse"
}
"xmlResponse"
</code>```

Body:
Yes, it is very much possible to mock using soapui.

Let us assume that when a rest service is invoked, it is possible to have different responses based on user's request header Content-Type value.

xmlResponse

jsonResponse

faultResponse

So, add above three responses to the mock service. And user SCRIPT as dispatcher.

Mock Service Script as follows:

def responseType = mockRequest.request.getHeader('Content-Type')
if (!responseType) {
    return "faultResponse"
}
if ('application/json' == responseType.toLowerCase() || 'json' == responseType.toLowerCase()) {
    return "jsonResponse"
}
"xmlResponse"


问:
No column in a table even after creation
I am making an app in Android Studio using java. I had created an internal database with two columns(name and productID) and everything was working just fine. when i added two more columns(Customer Name and Delivery date), it keeps crashing. The code for that activity is below as well as the logcat.

```<code>package com.kristar.busibooks;

import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import android.widget.Toast;

public class OrderActivity extends AppCompatActivity implements View.OnClickListener {

private EditText editCusTextName;
private EditText editTextName;
private EditText editTextAdd;
private EditText editDDTextName;
private Button btnAdd;
private Button btnView;
private Button btnCurrency;

private SQLiteDatabase db;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.content_order);

    createDatabase();

    editCusTextName = (EditText) findViewById(R.id.editCusTextName);
    editTextName = (EditText) findViewById(R.id.editTextName);
    editTextAdd = (EditText) findViewById(R.id.editTextpID);
    editDDTextName = (EditText) findViewById(R.id.editDDTextName);

    btnAdd = (Button) findViewById(R.id.btnAdd);
    btnView = (Button) findViewById(R.id.btnView);
    btnCurrency = (Button) findViewById(R.id.btnCurrency);

    btnAdd.setOnClickListener(this);
    btnView.setOnClickListener(this);
    btnCurrency.setOnClickListener(this);

    btnView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intentProduct = new Intent(getApplicationContext(), Products.class);
            startActivity(intentProduct);
        }
    });

    btnCurrency.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v){
            Intent intentCurrencyConverter = new Intent(getApplicationContext(), CurrencyConverter.class);
            startActivity(intentCurrencyConverter);
        }
    });

}

protected void createDatabase(){
    db=openOrCreateDatabase("ProductDB", Context.MODE_PRIVATE, null);
    db.execSQL("CREATE TABLE IF NOT EXISTS product(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, Custo_name VARCHAR, name VARCHAR,productID INT, Deli_Date DATE);");
}

protected void insertIntoDB(){
    String cus_name = editCusTextName.getText().toString().trim();
    String name = editTextName.getText().toString().trim();
    String add = editTextAdd.getText().toString().trim();
    String d_date = editDDTextName.getText().toString().trim();
    if(cus_name.equals("") || name.equals("") || add.equals("") || d_date.equals("")){
        Toast.makeText(getApplicationContext(),"Please fill all fields", Toast.LENGTH_LONG).show();
        return;
    }

    String query = "INSERT INTO product (Custo_name,name,productID,Deli_Date) VALUES('"+cus_name+"', '"+name+"', '"+add+"', '"+d_date+"');";
    db.execSQL(query);
    Toast.makeText(getApplicationContext(),"Saved Successfully", Toast.LENGTH_LONG).show();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@Override
public void onClick(View v) {
    if(v == btnAdd){
        insertIntoDB();
    }
}
</code>```

}

```<code>06-06 05:32:15.095 2362-2362/com.kristar.busibooks I/art: Not

late-enabling -Xcheck:jni (already on)
06-06 05:32:15.096 2362-2362/com.kristar.busibooks I/art: Late-enabling JIT
06-06 05:32:15.175 2362-2362/com.kristar.busibooks I/art: JIT created with code_cache_capacity=2MB compile_threshold=1000
06-06 05:32:15.592 2362-2362/com.kristar.busibooks W/System: ClassLoader referenced unknown path: /data/app/com.kristar.busibooks-2/lib/x86
06-06 05:32:16.065 2362-2373/com.kristar.busibooks I/art: WaitForGcToComplete blocked for 46.015ms for cause Background
06-06 05:32:17.134 2362-2376/com.kristar.busibooks D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
06-06 05:32:17.163 2362-2373/com.kristar.busibooks I/art: Background sticky concurrent mark sweep GC freed 9565(411KB) AllocSpace objects, 0(0B) LOS objects, 31% free, 2MB/3MB, paused 120.897ms total 1.085s
06-06 05:32:17.212 2362-2362/com.kristar.busibooks D/: HostConnection::get() New Host Connection established 0xab74d8e0, tid 2362
06-06 05:32:17.448 2362-2376/com.kristar.busibooks D/: HostConnection::get() New Host Connection established 0xab74dcb0, tid 2376
06-06 05:32:17.466 2362-2376/com.kristar.busibooks I/OpenGLRenderer: Initialized EGL, version 1.4
06-06 05:32:17.645 2362-2376/com.kristar.busibooks W/EGL_emulation: eglSurfaceAttrib not implemented
06-06 05:32:17.645 2362-2376/com.kristar.busibooks W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xabe7f900, error=EGL_SUCCESS
06-06 05:32:18.820 2362-2362/com.kristar.busibooks I/Choreographer: Skipped 64 frames!  The application may be doing too much work on its main thread.
06-06 05:32:24.125 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 7.568ms
06-06 05:32:24.333 2362-2376/com.kristar.busibooks W/EGL_emulation: eglSurfaceAttrib not implemented
06-06 05:32:24.333 2362-2376/com.kristar.busibooks W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xad6d1620, error=EGL_SUCCESS
06-06 05:32:24.682 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 35.944ms
06-06 05:32:26.172 2362-2362/com.kristar.busibooks I/Choreographer: Skipped 95 frames!  The application may be doing too much work on its main thread.
06-06 05:32:26.568 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 12.282ms
06-06 05:32:27.091 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 16.750ms
06-06 05:32:29.126 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 13.683ms
06-06 05:32:34.472 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 25.061ms
06-06 05:32:34.943 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 6.799ms
06-06 05:32:37.274 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 5.115ms
06-06 05:32:38.558 2362-2376/com.kristar.busibooks E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab755640
06-06 05:32:39.187 2362-2362/com.kristar.busibooks I/Choreographer: Skipped 201 frames!  The application may be doing too much work on its main thread.
06-06 05:32:41.686 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 27.114ms
06-06 05:32:45.302 2362-2376/com.kristar.busibooks W/EGL_emulation: eglSurfaceAttrib not implemented
06-06 05:32:45.302 2362-2376/com.kristar.busibooks W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xad6f0720, error=EGL_SUCCESS
06-06 05:32:45.485 2362-2376/com.kristar.busibooks E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab755640
06-06 05:32:46.455 2362-2376/com.kristar.busibooks W/EGL_emulation: eglSurfaceAttrib not implemented
06-06 05:32:46.455 2362-2376/com.kristar.busibooks W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xad6f0720, error=EGL_SUCCESS
06-06 05:32:46.551 2362-2376/com.kristar.busibooks E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab754920
06-06 05:32:46.703 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 77.331ms
06-06 05:32:46.739 2362-2362/com.kristar.busibooks I/Choreographer: Skipped 37 frames!  The application may be doing too much work on its main thread.
06-06 05:32:46.830 2362-2373/com.kristar.busibooks I/art: Background partial concurrent mark sweep GC freed 4946(325KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 3MB/5MB, paused 26.008ms total 568.072ms
06-06 05:32:47.154 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 37.891ms
06-06 05:32:47.737 2362-2362/com.kristar.busibooks I/Choreographer: Skipped 58 frames!  The application may be doing too much work on its main thread.
06-06 05:32:53.132 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 33.821ms
06-06 05:32:54.141 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 32.107ms
06-06 05:32:57.998 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 29.788ms
06-06 05:32:58.477 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 5.348ms
06-06 05:33:06.832 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 57.211ms
06-06 05:33:06.841 2362-2362/com.kristar.busibooks E/SQLiteLog: (1) table product has no column named Custo_name
06-06 05:33:06.842 2362-2362/com.kristar.busibooks D/AndroidRuntime: Shutting down VM
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime: FATAL EXCEPTION: main
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime: Process: com.kristar.busibooks, PID: 2362
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime: android.database.sqlite.SQLiteException: table product has no column named Custo_name (code 1): , while compiling: INSERT INTO product (Custo_name,name,productID,Deli_Date) VALUES('fg', 'gh', '56', '2017-11-12');
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1674)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at com.kristar.busibooks.OrderActivity.insertIntoDB(OrderActivity.java:91)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at com.kristar.busibooks.OrderActivity.onClick(OrderActivity.java:122)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.view.View.performClick(View.java:5198)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:21147)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:739)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-06 05:33:09.908 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 7.133ms
06-06 05:33:12.921 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 43.865ms
06-06 05:33:14.574 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 7.056ms
06-06 05:33:15.794 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 14.265ms
06-06 05:33:22.451 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 13.150ms
</code>```

答: Your table is already created without those columns when you first installed the app. You either need to upgrade your table and then add those columns or reinstall the app with the updated table schema.</p>

Body:
I am making an app in Android Studio using java. I had created an internal database with two columns(name and productID) and everything was working just fine. when i added two more columns(Customer Name and Delivery date), it keeps crashing. The code for that activity is below as well as the logcat.

package com.kristar.busibooks;

import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import android.widget.Toast;

public class OrderActivity extends AppCompatActivity implements View.OnClickListener {

private EditText editCusTextName;
private EditText editTextName;
private EditText editTextAdd;
private EditText editDDTextName;
private Button btnAdd;
private Button btnView;
private Button btnCurrency;

private SQLiteDatabase db;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.content_order);

    createDatabase();

    editCusTextName = (EditText) findViewById(R.id.editCusTextName);
    editTextName = (EditText) findViewById(R.id.editTextName);
    editTextAdd = (EditText) findViewById(R.id.editTextpID);
    editDDTextName = (EditText) findViewById(R.id.editDDTextName);

    btnAdd = (Button) findViewById(R.id.btnAdd);
    btnView = (Button) findViewById(R.id.btnView);
    btnCurrency = (Button) findViewById(R.id.btnCurrency);

    btnAdd.setOnClickListener(this);
    btnView.setOnClickListener(this);
    btnCurrency.setOnClickListener(this);

    btnView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intentProduct = new Intent(getApplicationContext(), Products.class);
            startActivity(intentProduct);
        }
    });

    btnCurrency.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v){
            Intent intentCurrencyConverter = new Intent(getApplicationContext(), CurrencyConverter.class);
            startActivity(intentCurrencyConverter);
        }
    });

}

protected void createDatabase(){
    db=openOrCreateDatabase("ProductDB", Context.MODE_PRIVATE, null);
    db.execSQL("CREATE TABLE IF NOT EXISTS product(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, Custo_name VARCHAR, name VARCHAR,productID INT, Deli_Date DATE);");
}

protected void insertIntoDB(){
    String cus_name = editCusTextName.getText().toString().trim();
    String name = editTextName.getText().toString().trim();
    String add = editTextAdd.getText().toString().trim();
    String d_date = editDDTextName.getText().toString().trim();
    if(cus_name.equals("") || name.equals("") || add.equals("") || d_date.equals("")){
        Toast.makeText(getApplicationContext(),"Please fill all fields", Toast.LENGTH_LONG).show();
        return;
    }

    String query = "INSERT INTO product (Custo_name,name,productID,Deli_Date) VALUES('"+cus_name+"', '"+name+"', '"+add+"', '"+d_date+"');";
    db.execSQL(query);
    Toast.makeText(getApplicationContext(),"Saved Successfully", Toast.LENGTH_LONG).show();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@Override
public void onClick(View v) {
    if(v == btnAdd){
        insertIntoDB();
    }
}

}

06-06 05:32:15.095 2362-2362/com.kristar.busibooks I/art: Not

late-enabling -Xcheck:jni (already on)
06-06 05:32:15.096 2362-2362/com.kristar.busibooks I/art: Late-enabling JIT
06-06 05:32:15.175 2362-2362/com.kristar.busibooks I/art: JIT created with code_cache_capacity=2MB compile_threshold=1000
06-06 05:32:15.592 2362-2362/com.kristar.busibooks W/System: ClassLoader referenced unknown path: /data/app/com.kristar.busibooks-2/lib/x86
06-06 05:32:16.065 2362-2373/com.kristar.busibooks I/art: WaitForGcToComplete blocked for 46.015ms for cause Background
06-06 05:32:17.134 2362-2376/com.kristar.busibooks D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
06-06 05:32:17.163 2362-2373/com.kristar.busibooks I/art: Background sticky concurrent mark sweep GC freed 9565(411KB) AllocSpace objects, 0(0B) LOS objects, 31% free, 2MB/3MB, paused 120.897ms total 1.085s
06-06 05:32:17.212 2362-2362/com.kristar.busibooks D/: HostConnection::get() New Host Connection established 0xab74d8e0, tid 2362
06-06 05:32:17.448 2362-2376/com.kristar.busibooks D/: HostConnection::get() New Host Connection established 0xab74dcb0, tid 2376
06-06 05:32:17.466 2362-2376/com.kristar.busibooks I/OpenGLRenderer: Initialized EGL, version 1.4
06-06 05:32:17.645 2362-2376/com.kristar.busibooks W/EGL_emulation: eglSurfaceAttrib not implemented
06-06 05:32:17.645 2362-2376/com.kristar.busibooks W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xabe7f900, error=EGL_SUCCESS
06-06 05:32:18.820 2362-2362/com.kristar.busibooks I/Choreographer: Skipped 64 frames!  The application may be doing too much work on its main thread.
06-06 05:32:24.125 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 7.568ms
06-06 05:32:24.333 2362-2376/com.kristar.busibooks W/EGL_emulation: eglSurfaceAttrib not implemented
06-06 05:32:24.333 2362-2376/com.kristar.busibooks W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xad6d1620, error=EGL_SUCCESS
06-06 05:32:24.682 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 35.944ms
06-06 05:32:26.172 2362-2362/com.kristar.busibooks I/Choreographer: Skipped 95 frames!  The application may be doing too much work on its main thread.
06-06 05:32:26.568 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 12.282ms
06-06 05:32:27.091 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 16.750ms
06-06 05:32:29.126 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 13.683ms
06-06 05:32:34.472 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 25.061ms
06-06 05:32:34.943 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 6.799ms
06-06 05:32:37.274 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 5.115ms
06-06 05:32:38.558 2362-2376/com.kristar.busibooks E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab755640
06-06 05:32:39.187 2362-2362/com.kristar.busibooks I/Choreographer: Skipped 201 frames!  The application may be doing too much work on its main thread.
06-06 05:32:41.686 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 27.114ms
06-06 05:32:45.302 2362-2376/com.kristar.busibooks W/EGL_emulation: eglSurfaceAttrib not implemented
06-06 05:32:45.302 2362-2376/com.kristar.busibooks W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xad6f0720, error=EGL_SUCCESS
06-06 05:32:45.485 2362-2376/com.kristar.busibooks E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab755640
06-06 05:32:46.455 2362-2376/com.kristar.busibooks W/EGL_emulation: eglSurfaceAttrib not implemented
06-06 05:32:46.455 2362-2376/com.kristar.busibooks W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xad6f0720, error=EGL_SUCCESS
06-06 05:32:46.551 2362-2376/com.kristar.busibooks E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab754920
06-06 05:32:46.703 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 77.331ms
06-06 05:32:46.739 2362-2362/com.kristar.busibooks I/Choreographer: Skipped 37 frames!  The application may be doing too much work on its main thread.
06-06 05:32:46.830 2362-2373/com.kristar.busibooks I/art: Background partial concurrent mark sweep GC freed 4946(325KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 3MB/5MB, paused 26.008ms total 568.072ms
06-06 05:32:47.154 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 37.891ms
06-06 05:32:47.737 2362-2362/com.kristar.busibooks I/Choreographer: Skipped 58 frames!  The application may be doing too much work on its main thread.
06-06 05:32:53.132 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 33.821ms
06-06 05:32:54.141 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 32.107ms
06-06 05:32:57.998 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 29.788ms
06-06 05:32:58.477 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 5.348ms
06-06 05:33:06.832 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 57.211ms
06-06 05:33:06.841 2362-2362/com.kristar.busibooks E/SQLiteLog: (1) table product has no column named Custo_name
06-06 05:33:06.842 2362-2362/com.kristar.busibooks D/AndroidRuntime: Shutting down VM
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime: FATAL EXCEPTION: main
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime: Process: com.kristar.busibooks, PID: 2362
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime: android.database.sqlite.SQLiteException: table product has no column named Custo_name (code 1): , while compiling: INSERT INTO product (Custo_name,name,productID,Deli_Date) VALUES('fg', 'gh', '56', '2017-11-12');
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1674)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at com.kristar.busibooks.OrderActivity.insertIntoDB(OrderActivity.java:91)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at com.kristar.busibooks.OrderActivity.onClick(OrderActivity.java:122)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.view.View.performClick(View.java:5198)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:21147)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:739)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5417)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
06-06 05:33:06.843 2362-2362/com.kristar.busibooks E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-06 05:33:09.908 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 7.133ms
06-06 05:33:12.921 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 43.865ms
06-06 05:33:14.574 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 7.056ms
06-06 05:33:15.794 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 14.265ms
06-06 05:33:22.451 2362-2369/com.kristar.busibooks W/art: Suspending all threads took: 13.150ms


问:
Convert JWT token created by Java JWT in python
I have received a JWT token created by a java program using jjwt module.
Now, when I try to verify the token using pyjwt, it throws exception.

```<code>import jwt token
token='eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMDAiLCJyb2xlcyI6IkJVU0lORVNTVVNFUiIsIm1vZGUiOiJzdG9yZWFwcCIsImlhdCI6MTQ5NDg1ODk4MCwiZXhwIjoxNDk0ODY0OTgwfQ.ckFnGv1NT-Ui2S90DNr50YoHSXc1ZLBNnEErnGMWL-E'
secret ='123456AB'
jwt.decode(token,secret,algorithms='HS256')
</code>```

Traceback (most recent call last):   File "", line 1, in
     File
  "/Applications/anaconda/envs/modulename/lib/python3.5/site-packages/jwt/api_jwt.py",
  line 64, in decode
      options, **kwargs)   File "/Applications/anaconda/envs/modulename/lib/python3.5/site-packages/jwt/api_jws.py",
  line 116, in decode
      key, algorithms)   File "/Applications/anaconda/envs/modulename/lib/python3.5/site-packages/jwt/api_jws.py",
  line 186, in _verify_signature
      raise DecodeError('Signature verification failed') jwt.exceptions.DecodeError: Signature verification failed

If i use the same token in jwt.io, with base64 encrypted option checked, it seems to work.

答: You may try to verify the signature of the incoming token in your Python application using the same SecretKey as you have used in your Java application.

Body:
I have received a JWT token created by a java program using jjwt module.
Now, when I try to verify the token using pyjwt, it throws exception.

import jwt token
token='eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMDAiLCJyb2xlcyI6IkJVU0lORVNTVVNFUiIsIm1vZGUiOiJzdG9yZWFwcCIsImlhdCI6MTQ5NDg1ODk4MCwiZXhwIjoxNDk0ODY0OTgwfQ.ckFnGv1NT-Ui2S90DNr50YoHSXc1ZLBNnEErnGMWL-E'
secret ='123456AB'
jwt.decode(token,secret,algorithms='HS256')

Traceback (most recent call last):   File "", line 1, in
     File
  "/Applications/anaconda/envs/modulename/lib/python3.5/site-packages/jwt/api_jwt.py",
  line 64, in decode
      options, **kwargs)   File "/Applications/anaconda/envs/modulename/lib/python3.5/site-packages/jwt/api_jws.py",
  line 116, in decode
      key, algorithms)   File "/Applications/anaconda/envs/modulename/lib/python3.5/site-packages/jwt/api_jws.py",
  line 186, in _verify_signature
      raise DecodeError('Signature verification failed') jwt.exceptions.DecodeError: Signature verification failed

If i use the same token in jwt.io, with base64 encrypted option checked, it seems to work.


问:
how to convert dataframe to RDD and don't change partition?
For some reason i have to convert RDD to dataframe,then do something with dataframe,but my interface is RDD,so i have to convert dataframe to RDD，when i use df.rdd,the partition change to 1,so i have to repartition and sortBy RDD,Is there any cleaner solution ?thanks!
this is my try:

```<code>    val rdd=sc.parallelize(List(1,3,2,4,5,6,7,8),4)
    val partition=rdd.getNumPartitions
    val sqlContext = new SQLContext(m_sparkCtx)
    import sqlContext.implicits._
    val df=rdd.toDF()
    df.rdd.zipWithIndex().sortBy(x => {x._2}, true, partition).map(x => {x._1})
</code>```

答:
Partitions should remain the same when you convert the DataFrame to an RDD.
For example when the rdd of 4 partitions is converted to DF and back the RDD the partitions of the RDD remains same as shown below.</p>

```<code>scala> val rdd=sc.parallelize(List(1,3,2,4,5,6,7,8),4)
rdd: org.apache.spark.rdd.RDD[Int] = ParallelCollectionRDD[11] at parallelize at <console>:27

scala> val partition=rdd.getNumPartitions
partition: Int = 4

scala> val df=rdd.toDF()
df: org.apache.spark.sql.DataFrame = [value: int]

scala> df.rdd.getNumPartitions
res1: Int = 4

scala> df.withColumn("col2", lit(10)).rdd.getNumPartitions
res1: Int = 4
</code>```

Body:
For some reason i have to convert RDD to dataframe,then do something with dataframe,but my interface is RDD,so i have to convert dataframe to RDD，when i use df.rdd,the partition change to 1,so i have to repartition and sortBy RDD,Is there any cleaner solution ?thanks!
this is my try:

    val rdd=sc.parallelize(List(1,3,2,4,5,6,7,8),4)
    val partition=rdd.getNumPartitions
    val sqlContext = new SQLContext(m_sparkCtx)
    import sqlContext.implicits._
    val df=rdd.toDF()
    df.rdd.zipWithIndex().sortBy(x => {x._2}, true, partition).map(x => {x._1})

Body:
Partitions should remain the same when you convert the DataFrame to an RDD.
For example when the rdd of 4 partitions is converted to DF and back the RDD the partitions of the RDD remains same as shown below.

scala> val rdd=sc.parallelize(List(1,3,2,4,5,6,7,8),4)
rdd: org.apache.spark.rdd.RDD[Int] = ParallelCollectionRDD[11] at parallelize at <console>:27

scala> val partition=rdd.getNumPartitions
partition: Int = 4

scala> val df=rdd.toDF()
df: org.apache.spark.sql.DataFrame = [value: int]

scala> df.rdd.getNumPartitions
res1: Int = 4

scala> df.withColumn("col2", lit(10)).rdd.getNumPartitions
res1: Int = 4


问:
Writing data to a single sheet of excel using MATLAB
I am working on two column text file and want to save the result of subtraction of two columns in a excel file in a single sheet. I worked on following code but the program below is writing the difference in separate sheet in a single workbook, and I need all 50 (difference) in a single sheet. Please help me. Thank you.      </p>

```<code>close all;
for k = 1:9
filename = sprintf('Data_F_Ind000%d.txt',k);
data = load (filename);
f = data(:,1) - data (:,2);
xlswrite('difference_1_9.xlsx',f,1);
end
</code>```

答:
You can store all your results into a matrix and then after write to excel. Check the below pseudo code.</p>

```<code>N = 10 ; % your number of lines in data/ each file
nfiles = 9 ;   % number of files
iwant = zeros(N,nfiles) ;
for i = 1:nfiles
    data = rand(N,2) ;
    iwant(:,i) = data(:,1)-data(:,2) ;
end
myfile = 'myfile.xlsx' ;

xlswrite(myfile,iwant)
</code>```

Body:
I am working on two column text file and want to save the result of subtraction of two columns in a excel file in a single sheet. I worked on following code but the program below is writing the difference in separate sheet in a single workbook, and I need all 50 (difference) in a single sheet. Please help me. Thank you.

close all;
for k = 1:9
filename = sprintf('Data_F_Ind000%d.txt',k);
data = load (filename);
f = data(:,1) - data (:,2);
xlswrite('difference_1_9.xlsx',f,1);
end

Body:
You can store all your results into a matrix and then after write to excel. Check the below pseudo code.

N = 10 ; % your number of lines in data/ each file
nfiles = 9 ;   % number of files
iwant = zeros(N,nfiles) ;
for i = 1:nfiles
    data = rand(N,2) ;
    iwant(:,i) = data(:,1)-data(:,2) ;
end
myfile = 'myfile.xlsx' ;

xlswrite(myfile,iwant)


问:
Data bind ObservableCollection<XElement> to a ListBox?
I'm developing a Silverlight application, and want to set the ItemsSource of a ListBox to ObeservableCollection<XElement>  and still be able to use the Binding Path=Element[name].Value syntax to get values for a data template. I can get the binding successfully, but the Element[] syntax is not working. It just renders empty. For example, this does not work:

```<code><DataTemplate x:Key="SearchResultsTemplate">
    <ListBox ItemsSource="{Binding}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBlock Text="{Binding Path=Element[key].Value}" />
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</DataTemplate>
</code>```

But oddly, something like this does render content, which tells me everything is bound to some degree, but something is keeping me from using the Element dynamic property:

```<code><DataTemplate x:Key="SearchResultsTemplate">
    <ListBox ItemsSource="{Binding}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBlock Text="{Binding Path=FirstNode}" />
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</DataTemplate>
</code>```

What am I doing wrong?

答:
The Element pseudoproperty is only available in the desktop version of .NET. It relies on the type descriptor system which is one of the pieces of the .NET Framework that's missing in Silverlight.

In the full .NET framework, XElement has a [TypeDescriptionProvider(typeof(XTypeDescriptionProvider<XElement>))] attribute, which is how those Element and other pseudoproperties are exposed to databinding. This attribute is not present in the Silverlight version of XElement. (And it can't be present because Silverlight doesn't provide a definition of TypeDescriptionProvider, or any of the associated machinery behind that attribute.

Silverlight doesn't provide a direct way to bind to XML content. (It doesn't support XPath either, which is the other solution popular in WPF.) You could look at Binding XML in Silverlight without nominal classes which links to an article by Graham Murray which shows how to generate bindable types dynamically.

That's a relatively complex solution though. I think I'd just write a wrapper type for the XML that includes the data I want, and use LINQ to XML to populate those wrappers from the XML.

Body:
I'm developing a Silverlight application, and want to set the ItemsSource of a ListBox to ObeservableCollection<XElement>  and still be able to use the Binding Path=Element[name].Value syntax to get values for a data template. I can get the binding successfully, but the Element[] syntax is not working. It just renders empty. For example, this does not work:

<DataTemplate x:Key="SearchResultsTemplate">
    <ListBox ItemsSource="{Binding}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBlock Text="{Binding Path=Element[key].Value}" />
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</DataTemplate>

But oddly, something like this does render content, which tells me everything is bound to some degree, but something is keeping me from using the Element dynamic property:

<DataTemplate x:Key="SearchResultsTemplate">
    <ListBox ItemsSource="{Binding}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel>
                    <TextBlock Text="{Binding Path=FirstNode}" />
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</DataTemplate>

What am I doing wrong?


问:
how to combine two text in one array
```<code>vowels=["a","e","i","o","u"]
word=["a","ir","the","book"]
for i in word:
    if len(i) == 1 and i in vowels:
        ....
</code>```

I just make this loop to detect 'a' in 'vowels' array and have only one space

like 'a' = 1 space , 'ant' = 3 spaces.

I want to combine 'a' with the following word in array.

how can I combine 'a' with 'ir' to make 'word' array to be

```<code>word=["air","the","book"]
</code>```

答:
```<code>>>> vowels = {'a', 'e', 'i', 'o', 'u'}  # used set for efficient `in` operation
>>> words = ['a', 'ir', 'the', 'book']
>>> for i in range(len(words) - 2, -1, -1):
...     if words[i] in vowels:
...         # len(words[i]) == 1 is redundant (all vowels items' length = 1)
...         words[i] += words.pop(i + 1)  # merge vowel with next word
...
>>> words
['air', 'the', 'book']
</code>```

NOTE: iterated backward; otherwise indexes are broken as soon as list.pop called.

Title: how to combine two text in one array

Body:
vowels=["a","e","i","o","u"]
word=["a","ir","the","book"]
for i in word:
    if len(i) == 1 and i in vowels:
        ....

I just make this loop to detect 'a' in 'vowels' array and have only one space

like 'a' = 1 space , 'ant' = 3 spaces.

I want to combine 'a' with the following word in array.

how can I combine 'a' with 'ir' to make 'word' array to be

word=["air","the","book"]

Body:
>>> vowels = {'a', 'e', 'i', 'o', 'u'}  # used set for efficient `in` operation
>>> words = ['a', 'ir', 'the', 'book']
>>> for i in range(len(words) - 2, -1, -1):
...     if words[i] in vowels:
...         # len(words[i]) == 1 is redundant (all vowels items' length = 1)
...         words[i] += words.pop(i + 1)  # merge vowel with next word
...
>>> words
['air', 'the', 'book']

NOTE: iterated backward; otherwise indexes are broken as soon as list.pop called.


问:
Unable to iterate a list and compare strings python
I am new to python programming and I really need help in comparing values in a list.

I have two lists(drink,food) .I'm not doing a comparison between two lists. What i am trying to do is comparing all the values within a list by itself.

So, I have to first compare all the values in drink list first using a for loop and an if-else statement. If there's a match in drink, I will do another for loop for food list and compare the values in food list using an if-else statement.

These are my code:

```<code>drinks = []
food = []

drinks.append("lemontea")
drinks.append("coke")
drinks.append("sprite")
drinks.append("orangejuice")
drinks.append("fantagrape")

food.append("nugget")
food.append("pizza")
food.append("chickenwing")
food.append("fries")
food.append("pizza")

for i in drinks:
    if i == drinks:
        for j in food:
            if j == food:
                print("fail")
    else:
         print("success")
</code>```

My issue is that I am supposed to be getting an 'failed' output as I have the same item in the food list that is pizza. Also, i'm not sure why am i getting 5 success output when im expected to get either only 1 'failed' or 'success' output.

This is my output i got:

```<code>success
success
success
success
success
</code>```

I would appreciate if any help was given. Thank you.

Update:
Thanks for the reply but however, it seem that people are confused with my question, hence im providing more information.

The reason why i have to compare each item in a list is because the items are generated randomly and are of string type which are then appended to the list. For example, the first item generated is '00100ABC'and so on. So in case, there are duplicate values/item in the list, i have to give an error message.

答:
This prints on success and failure and also removes duplicates…</p>

```<code>drinks = []
food = []

food.append("nugget")
food.append("pizza")
food.append("chickenwing")
food.append("fries")
food.append("pizza")

# let's add some duplicates…
drinks.append("lemontea")
drinks.append("fantagrape")
drinks.append("fantagrape")
drinks.append("coke")
drinks.append("orangejuice")
drinks.append("sprite")
drinks.append("fantagrape")
drinks.append("lemontea")
drinks.append("fantagrape")
drinks.append("sprite")
drinks.append("sprite")
drinks.append("orangejuice")
drinks.append("orangejuice")
drinks.append("coke")
drinks.append("coke")

food.append("chickenwing")
food.append("nugget")
food.append("pizza")
food.append("fries")
food.append("chickenwing")
food.append("nugget")
food.append("fries")
food.append("pizza")

for drink in drinks:
  occurences = [index for index, value in enumerate(drinks) if value == drink]
  if len(occurences) > 1:  # if duplicates occur
    print('fail: {}'.format(drink))
    occurences.pop()  # keep one occurence
    [drinks.remove(drink) for o in occurences]  # remove the rest
  else:
    print('success: {}'.format(drink))

for meal in food:
  occurences = [index for index, value in enumerate(food) if value == meal]
  if len(occurences) > 1:  # if duplicates occur
    print('fail: {}'.format(meal))
    occurences.pop()  # keep one occurence
    [food.remove(meal) for o in occurences]  # remove the rest
  else:
    print('success: {}'.format(meal))

print(drinks)
print(food)
</code>```

Body:
I am new to python programming and I really need help in comparing values in a list.

I have two lists(drink,food) .I'm not doing a comparison between two lists. What i am trying to do is comparing all the values within a list by itself.

So, I have to first compare all the values in drink list first using a for loop and an if-else statement. If there's a match in drink, I will do another for loop for food list and compare the values in food list using an if-else statement.

These are my code:

drinks = []
food = []

drinks.append("lemontea")
drinks.append("coke")
drinks.append("sprite")
drinks.append("orangejuice")
drinks.append("fantagrape")

food.append("nugget")
food.append("pizza")
food.append("chickenwing")
food.append("fries")
food.append("pizza")

for i in drinks:
    if i == drinks:
        for j in food:
            if j == food:
                print("fail")
    else:
         print("success")

My issue is that I am supposed to be getting an 'failed' output as I have the same item in the food list that is pizza. Also, i'm not sure why am i getting 5 success output when im expected to get either only 1 'failed' or 'success' output.

This is my output i got:

success
success
success
success
success

I would appreciate if any help was given. Thank you.

Update:
Thanks for the reply but however, it seem that people are confused with my question, hence im providing more information.

The reason why i have to compare each item in a list is because the items are generated randomly and are of string type which are then appended to the list. For example, the first item generated is '00100ABC'and so on. So in case, there are duplicate values/item in the list, i have to give an error message.

Body:
This prints on success and failure and also removes duplicates…

drinks = []
food = []

food.append("nugget")
food.append("pizza")
food.append("chickenwing")
food.append("fries")
food.append("pizza")

# let's add some duplicates…
drinks.append("lemontea")
drinks.append("fantagrape")
drinks.append("fantagrape")
drinks.append("coke")
drinks.append("orangejuice")
drinks.append("sprite")
drinks.append("fantagrape")
drinks.append("lemontea")
drinks.append("fantagrape")
drinks.append("sprite")
drinks.append("sprite")
drinks.append("orangejuice")
drinks.append("orangejuice")
drinks.append("coke")
drinks.append("coke")

food.append("chickenwing")
food.append("nugget")
food.append("pizza")
food.append("fries")
food.append("chickenwing")
food.append("nugget")
food.append("fries")
food.append("pizza")

for drink in drinks:
  occurences = [index for index, value in enumerate(drinks) if value == drink]
  if len(occurences) > 1:  # if duplicates occur
    print('fail: {}'.format(drink))
    occurences.pop()  # keep one occurence
    [drinks.remove(drink) for o in occurences]  # remove the rest
  else:
    print('success: {}'.format(drink))

for meal in food:
  occurences = [index for index, value in enumerate(food) if value == meal]
  if len(occurences) > 1:  # if duplicates occur
    print('fail: {}'.format(meal))
    occurences.pop()  # keep one occurence
    [food.remove(meal) for o in occurences]  # remove the rest
  else:
    print('success: {}'.format(meal))

print(drinks)
print(food)