问题列表 - 第40491页

19
推荐指数
2
解决办法
1万
查看次数

python排序列表与铸造

我知道几次已经问过类似的问题了.我现在做了如何使用搜索功能,但它仍然无法正常工作.

所以这是问题设置.我有一个包含字符串的列表列表.一列包含实际表示浮点值的字符串.它也是我想要排序的列.问题是,python似乎忽略条目上的 - (减号)符号.所以一个示例列表:

[[blaa, '0.3', bli], [bla, '0.1', blub], [bla, '-0.2', blub]]
Run Code Online (Sandbox Code Playgroud)

像这样排序:

[[bla, '0.1', blub], [bla, '-0.2', blub], [blaa, '0.3', bli]]
Run Code Online (Sandbox Code Playgroud)

而不是它应该如何:

[[bla, '-0.2', blub],[bla, '0.1', blub], [blaa, '0.3', bli]]
Run Code Online (Sandbox Code Playgroud)

到目前为止我尝试过:

  • 将第二列转换为浮动并按该列排序

喜欢:

for i in mylist:
  i[1] = float(i[1])    

mylist.sort(key=lambda x: x[1])
Run Code Online (Sandbox Code Playgroud)

或者

for i in mylist:
  i[1] = float(i[1]) 

mylist.sort(key=operator.itemgetter(1))
Run Code Online (Sandbox Code Playgroud)
  • 我还尝试定义自己的比较函数:

喜欢:

mylist.sort(cmp=lambda x,y: cmp(float(x), float(y)), key=operator.itemgetter(1))
Run Code Online (Sandbox Code Playgroud)

和上述方法的任何其他组合,也一样sorted.到目前为止,没有成功,每次都会忽略减号.怎么解决这个?

[编辑] 也已经尝试过Ignacio的建议.我应该提到我必须使用python 2.5.

python sorting

14
推荐指数
1
解决办法
1万
查看次数

如何在IIS6中创建子域

我对域和子域的配置都很陌生.

我已经有一个属于域名"www.foo.es"的子域名"bar".当我想访问子域时,我只需要输入"www.foo.es/bar",到目前为止一切都还好.

我打算做的是输入subdominion键入"bar.foo.es".

我尝试过一些我在网上找到的东西,但都没有.你能告诉我怎么做或者至少给我一些实际工作的线索或教程吗?

我正在尝试使用IIS6属性设置所有(不是动态的,因为它不是用户的东西,只是我想要"直接"访问的子域.

dns iis-6

2
推荐指数
1
解决办法
1万
查看次数

@Service构造了两次

我的Spring应用程序有问题,我的@Service类在应用程序启动时被创建了两次.我知道这是我的配置问题,因为我之前已经经历过,但究竟我做错了什么?

我在下面列出配置的方式有什么根本原因吗?(我已经省略了我认为无关紧要的一切)

web.xml中:

<servlet>
    <servlet-name>myapp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>myapp</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/myapp-config.xml
        /WEB-INF/myapp-security.xml
        /WEB-INF/myapp-mvc.xml
    </param-value>
</context-param>

<listener>
    <listener-class>com.myapp.servlet.MyAppContextListener</listener-class>
</listener>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)

MYAPP-servlet.xml中

<context:component-scan base-package="com.myapp" annotation-config="true" />
<mvc:annotation-driven />
Run Code Online (Sandbox Code Playgroud)

MYAPP-config.xml中

<context:component-scan base-package="com.myapp" annotation-config="true" />
<context:annotation-config />
Run Code Online (Sandbox Code Playgroud)

spring spring-mvc

28
推荐指数
3
解决办法
1万
查看次数

当模型已经存在时,如何运行`rails generate scaffold`?

我是Rails的新手,所以我目前的项目处于一种奇怪的状态.

我生成的第一件事是"电影"模型.然后我开始更详细地定义它,添加了一些方法等.

我现在意识到我应该生成它rails generate scaffold来连接诸如路由,视图,控制器等的东西.

我试图生成脚手架,但我收到一个错误,说已存在同名的迁移文件.

现在为我的"电影"创建脚手架的最佳方式是什么?(使用导轨3)

ruby-on-rails ruby-on-rails-3

325
推荐指数
7
解决办法
13万
查看次数

String.Replace在运行时不替换字符串

以下代码中的以下行不会产生任何影响:

string1.Replace(string1.Substring(firstchar, lastchar - firstchar), "##");
Run Code Online (Sandbox Code Playgroud)

string1 保持不变,使用IndexOf时返回相同的索引.

while (firstchar != string1.LastIndexOf("test"))
{

    firstchar = string1.IndexOf("test");
    lastchar = string1.IndexOf(" ");
    using (StreamWriter writer = new StreamWriter("C:\\textfile1.txt"))
    {
        writer.WriteLine(string1.Substring(firstchar, lastchar - firstchar));
        writer.WriteLine();
        writer.Dispose();
    }
    string1.Replace(string1.Substring(firstchar, lastchar - firstchar), "##");

}
Run Code Online (Sandbox Code Playgroud)

.net c# string

2
推荐指数
2
解决办法
3058
查看次数

如何在Linq做一个简单的计数?

我想做一个分页样式表,但是NeerDinner示例将整个数据提取到一个PaggingList类型中,并且我有超过10 000行要提取,所以我跳过了那一部分.

所以我想出了这个问题

var r = (from p in db.Prizes
            join c in db.Calendars on p.calendar_id equals c.calendar_id
            join ch in db.Challenges on c.calendar_id equals ch.calendar_id
            join ca in db.ChallengeAnswers on ch.challenge_id equals ca.challenge_id
            join cr in db.ChallengeResponses on ca.challenge_answer_id equals cr.challenge_answer_id

            where
                p.prize_id.Equals(prizeId)
                && ch.day >= p.from_day && ch.day <= p.to_day
                && ca.correct.Equals(true)
                && ch.day.Equals(day)

            orderby cr.Subscribers.name

            select new PossibleWinner()
            {
                Name = cr.Subscribers.name,
                Email = cr.Subscribers.email,
                SubscriberId = cr.subscriber_id,
                ChallengeDay = ch.day,
                Question = ch.question,
                Answer …
Run Code Online (Sandbox Code Playgroud)

linq ado.net linq-to-entities entity-framework

5
推荐指数
1
解决办法
1万
查看次数

.NET Web应用程序的尖端技术?

如果您想构建最昂贵的Web应用程序,您会使用什么?没有购买除VS2010和SQL Server数据库之外的Microsoft产品.

增值是否在于您使用的技术和应用的架构模式?

如果是这样,在所有应用程序层中的.NET技术中使用什么来增加网站价值?

我问这个是因为我有商机,我没有钱投资,因此我希望通过技术贡献来支付我的合作伙伴的投资.

非常感谢.

.net c# asp.net-mvc-2

2
推荐指数
1
解决办法
1298
查看次数

是方检吗?

我正在尝试编写函数来检查参数是否为整数的平方:

isSquare :: Int -> Bool
isSquare x = truncate(sqrt(x)) * truncate(sqrt(x)) == x
Run Code Online (Sandbox Code Playgroud)

当我加载该函数时,我得到错误:

Prelude> :load "some.hs"
[1 of 1] Compiling Main             ( some.hs, interpreted )

some.hs:2:13:
    No instance for (RealFrac Int)
      arising from a use of `truncate' at some.hs:2:13-29
    Possible fix: add an instance declaration for (RealFrac Int)
    In the first argument of `(*)', namely `truncate (sqrt (x))'
    In the first argument of `(==)', namely
        `truncate (sqrt (x)) * truncate (sqrt (x))'
    In the expression: truncate (sqrt (x)) …
Run Code Online (Sandbox Code Playgroud)

haskell

4
推荐指数
1
解决办法
3599
查看次数

装饰模式问题C#/ java

我正在看这篇维基百科文章,无法理解这是怎么回事.有点沮丧只是通过查看它无法理解代码,我决定将代码移植到c#(我是.net,对不起家伙:)).只需要一些小修改(继承和扩展,基于超级等)并运行应用程序.令我惊讶的是,我得到了以下输出:

Cost: 1 Ingredient: Coffee
Cost: 1 Ingredient: Coffee
Cost: 1 Ingredient: Coffee
Cost: 1 Ingredient: Coffee
Run Code Online (Sandbox Code Playgroud)

只是好奇,任何java开发都可以告诉我这里有什么不同以及为什么维基百科示例有效(如果它确实有效,就像它们所说的那样).

    namespace ConsoleApplication1
{
 class Program
 {
  static void Main(string[] args)
  {

  Coffee sampleCoffee = new SimpleCoffee();
  Console.WriteLine("Cost: " + sampleCoffee.getCost() + " Ingredient: " + sampleCoffee.getIngredient());

        sampleCoffee = new Milk(sampleCoffee);
        Console.WriteLine("Cost: " + sampleCoffee.getCost() + " Ingredient: " + sampleCoffee.getIngredient());

        sampleCoffee = new Sprinkles(sampleCoffee);
        Console.WriteLine("Cost: " + sampleCoffee.getCost() + " Ingredient: " + sampleCoffee.getIngredient());

        sampleCoffee = new Whip(sampleCoffee);
        Console.WriteLine("Cost: " …
Run Code Online (Sandbox Code Playgroud)

c# java design-patterns decorator

5
推荐指数
1
解决办法
915
查看次数