如何更改具有以下元素的列表:
package com.MyWebApp.controller.servlet.filters.tracking;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
//import javax.servlet.annotation.WebFilter;
//@WebFilter("/TrackingFilter")
public class TrackingFilter implements Filter{
private FilterConfig config = null;
public void init(FilterConfig config) throws ServletException{
this.config = config;
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
System.out.println("HELLO WORLD FROM - MYFILTER");
System.out.println("GOODBYE CRUEL WORLD - EXIT MYFILTER ");
}
public void destroy() {}
}
收件人:
<filter-mapping>
<filter-name>TrackingFilter</filter-name>
<!-- <url-pattern>/*</url-pattern> -->
<url-pattern>/AppointmentApp/*</url-pattern>
</filter-mapping>
答案 0 :(得分:1)
您可以使用此:
>>> [[i for i in days if not isinstance(i, list)]] + [i for i in days if isinstance(i, list)][0]
[['Mon', 'Tues', 'Wed', 'Thur', 'Fri'], 'Sat', 'Sun']
>>>
答案 1 :(得分:0)
l = []
temp = []
for i in days:
if isinstance(i, list):
l.append(temp)
temp = []
for j in i:
l.append(j)
else:
temp.append(i)
if temp:
l.append(temp)
print(l)
输出:
[['Mon', 'Tues', 'Wed', 'Thur', 'Fri'], 'Sat', 'Sun']
答案 2 :(得分:0)
由于似乎没有任何规则,该怎么做?
>>> days = ['Mon', 'Tues', 'Wed', 'Thur', 'Fri', ['Sat', 'Sun']]
>>> [days[:-1]] + days[-1]
[['Mon', 'Tues', 'Wed', 'Thur', 'Fri'], 'Sat', 'Sun']
>>>