[Tutor] input and raw input

John Chandler oldmantaggie at gmail.com
Sat Sep 25 15:33:06 CEST 2010


you can use an re split...

import re
a=raw_input("Enter the number of your class in the school:")
regex = re.compile("[ ,]") #sets the delimeters to a single space or comma
m = regex.split(a)

if you want to use any white space character than you can use "[\s,]"

2010/9/23 Ahmed AL-Masri <ahmedn82 at hotmail.com>

>  Hi,
> any one have an idea about how we can input many number in the one time and
> change it to list.
> for example:
>
> a=input("Enter the number of your class in the school:")     # the number
> can be enter as: 12,13,14 or 12 13 14 with a space in between.
>
> now how I can put these numbers into list like b=[12,13,14] with len( a )
> =3
>
> I tried with that but it's working only for a numbers less than 10 ex.
> 1,2,3 or 1 2 3 but it's not when I go for numbers higher than 10 like in
> example above.
>
> a=raw_input("Enter the number of your class in the school:")
> m=[]
>  for I range (len( a)):
>     if a[I]==',':
>         pass
>     elif a[I]==' ':
>         pass
>     else:
>         m.append(a[I])
> m=map(float,m)
> print m;print len( m )
> >> [1,2,3]
> >> 3
>
> looking forward to seeing your help,
> regards,
> Ahmed
>
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
-John Chandler
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100925/fa23b62b/attachment.html>


More information about the Tutor mailing list