Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7039851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:50:53+00:00 2026-05-28T01:50:53+00:00

Say I got a string: s = ”’1 2 3 4 5 6 7

  • 0

Say I got a string:

s = '''1 2 3
4 5 6
7 8 9
'''

I want to turn each line of string s into a list of floating-point value, that is:

l = [[1.0 2.0 3.0], [4.0 5.0 6.0], [7.0 8.0 9.0]]

How can I do this in one line?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:50:54+00:00Added an answer on May 28, 2026 at 1:50 am
    s = '''1 2 3
    4 5 6
    7 8 9'''
    
    l = [ map( float, i.strip().split(" ") ) for i in s.split( "\n" ) ] 
    

    Note strip isn’t needed when there isn’t ‘loose’ spaces.
    Strip works as trim eg. in php .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I've got: Dim los1 as New List(Of String) los1.Add(Some value) Dim los2
Let´s say I´ve got the following xml string: <Item Name=\$Resources:myresource,somestring;\</Item> Now I want to
Say I've got a class where the sole data member is something like std::string
Say I've got two scheduled processes: A and B. Given that B should not
Say I've got a bunch of files that are all >100 lines long. I'd
Let's say I've got a Java object that's got among others the following methods:
I've got a variable, let's say $x and it holds the value of website.com
I've got a String array that I'm wanting to add to a string builder
What's the simplest way to read a registry key value to std::String? Say I've
Let's say I have a string like: $text = <object>item_id1a2b3</object>xxx<object>item_id4c5d6</object> I want to convert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.